编辑代码

json='{"name": "John", "age": 30, "city": "New York"}'
name=$(echo $json | awk -F'"' '{print $4}')
age=$(echo $json | awk -F':' '{print $3}' | awk -F',' '{print $1}')
city=$(echo $json | awk -F'"' '{print $8}')
echo "Name: $name"
echo "Age: $age"
echo "City: $city"

# 城厢location=101230407    莆田location=101230401 


# ********************************************************************************************************************
# ********************************************************************************************************************
#实时天气
nowWeather=$(curl -s -L -X GET --compressed \
'https://devapi.qweather.com/v7/weather/now?location=101230401&key=c2f8a31f1f36400c878d359188357c0d')
#现在天气
#text=$(echo $nowWeather | awk -F'"text":' '{print $2}' | awk -F',' '{print $1}')
#echo $text
#当前实时温度(非今日)
temp=$(echo $nowWeather | awk -F'"temp":' '{print $2}' | awk -F',' '{print $1}')
echo "当前实时温度" $temp
#当前风向
windDir=$(echo $nowWeather | awk -F'"windDir":' '{print $2}' | awk -F',' '{print $1}')
echo "当前风向" $windDir
#当前风力
windScale=$(echo $nowWeather | awk -F'"windScale":' '{print $2}' | awk -F',' '{print $1}')
echo "当前风力" $windScale



# ********************************************************************************************************************
# ********************************************************************************************************************
#当前空气质量
airNow=$(curl -s -L -X GET --compressed \
'https://devapi.qweather.com/v7/air/now?location=101230401&key=c2f8a31f1f36400c878d359188357c0d')
#当前空气质量
airNowCategory=$(echo $airNow | awk -F'"category":' '{print $2}' | awk -F',' '{print $1}')
echo "当前空气质量" $airNowCategory



# ********************************************************************************************************************
# ********************************************************************************************************************
#近三天天气
threeDaysWeather=$(curl -s -L -X GET --compressed \
'https://devapi.qweather.com/v7/weather/3d?location=101230401&key=c2f8a31f1f36400c878d359188357c0d')
#今天天气
todayTextDay=$(echo $threeDaysWeather | awk -F'"textDay":' '{print $2}' | awk -F',' '{print $1}')
echo "今天天气" $todayTextDay
#今天最低温度
todayTempMin=$(echo $threeDaysWeather | awk -F'"tempMin":' '{print $2}' | awk -F',' '{print $1}')
echo "今天最低温度" $todayTempMin
#今天最高温度
todayTempMax=$(echo $threeDaysWeather | awk -F'"tempMax":' '{print $2}' | awk -F',' '{print $1}')
echo "今天最高温度" $todayTempMax
#今天温差
todayTempGap=$(($(echo $todayTempMax | tr -d '"')-$(echo $todayTempMin | tr -d '"')))
echo "今天温差" $todayTempGap

#明天天气
tomorrowTextDay=$(echo $threeDaysWeather | awk -F'"textDay":' '{print $3}' | awk -F',' '{print $1}')
echo "明天天气" $tomorrowTextDay
#明天最低温度
tomorrowTempMin=$(echo $threeDaysWeather | awk -F'"tempMin":' '{print $3}' | awk -F',' '{print $1}')
echo "明天最低温度" $tomorrowTempMin
#明天最高温度
tomorrowTempMax=$(echo $threeDaysWeather | awk -F'"tempMax":' '{print $3}' | awk -F',' '{print $1}')
echo "明天最低温度" $tomorrowTempMax
#明天温差
tomowwrowTempGap=$(($(echo $tomorrowTempMax | tr -d '"')-$(echo $tomorrowTempMin | tr -d '"')))
echo "明天温差" $tomowwrowTempGap


finalWeather="当前温度"$temp"度。天气"$todayTextDay","$windDir$windScale"级,空气质量"$airNowCategory",今天气温"$todayTempMin"到"$todayTempMax"度,昼夜温差"$todayTempGap"度,明天天气"$tomorrowTextDay",气温"$tomorrowTempMin"到"$tomorrowTempMax"度,昼夜温差"$tomowwrowTempGap"度"
finalWeatherMix=$(echo $finalWeather | tr -d '"')
echo $finalWeatherMix
espeak -vzh $finalWeather

# 最终格式   当前温度13度  天气晴 东北风3级 空气质量优 7到15度 昼夜温差8度     明天天气晴 9到15度 昼夜温差6度