标签:cas net tps ash inux 今天 script pool 朋友
yum -y install jq[sqoop@uhadoop-mzwc2w-task3 weather]$ pwd
/home/sqoop/scripts/weather
You have new mail in /var/spool/mail/sqoop
[sqoop@uhadoop-mzwc2w-task3 weather]$ cat weather.sh
#!/bin/bash
echo ‘--------------------------------------------------------------------------------------------------------‘
#json=`curl -s http://t.weather.sojson.com/api/weather/city/101230101`
json=`curl -s http://t.weather.sojson.com/api/weather/city/101020100`
echo $json > /home/sqoop/scripts/weather/weather.json
json=$(cat /home/sqoop/scripts/weather/weather.json)
city=`echo $json | jq ‘.cityInfo.city‘ | sed ‘s/\"//g‘ `
wendu=`echo $json | jq ‘.data.wendu‘ | sed ‘s/\"//g‘ `
shidu=`echo $json | jq ‘.data.shidu‘ | sed ‘s/\"//g‘ `
quality=`echo $json | jq ‘.data.quality‘ | sed ‘s/\"//g‘ `
ganmao=`echo $json | jq ‘.data.ganmao‘ | sed ‘s/\"//g‘ `
high=`echo $json | jq ‘.data.forecast[0].high‘ | sed ‘s/\"//g‘ `
low=`echo $json | jq ‘.data.forecast[0].low‘ | sed ‘s/\"//g‘ `
fx=`echo $json | jq ‘.data.forecast[0].fx‘ | sed ‘s/\"//g‘ `
fl=`echo $json | jq ‘.data.forecast[0].fl‘ | sed ‘s/\"//g‘ `
type=`echo $json | jq ‘.data.forecast[0].type‘ | sed ‘s/\"//g‘ `
notice=`echo $json | jq ‘.data.forecast[0].notice‘ | sed ‘s/\"//g‘ `
high2=`echo $json | jq ‘.data.forecast[1].high‘ | sed ‘s/\"//g‘ `
low2=`echo $json | jq ‘.data.forecast[1].low‘ | sed ‘s/\"//g‘ `
fx2=`echo $json | jq ‘.data.forecast[1].fx‘ | sed ‘s/\"//g‘ `
fl2=`echo $json | jq ‘.data.forecast[1].fl‘ | sed ‘s/\"//g‘ `
type2=`echo $json | jq ‘.data.forecast[1].type‘ | sed ‘s/\"//g‘ `
notice2=`echo $json | jq ‘.data.forecast[1].notice‘ | sed ‘s/\"//g‘ `
high3=`echo $json | jq ‘.data.forecast[2].high‘ | sed ‘s/\"//g‘ `
low3=`echo $json | jq ‘.data.forecast[2].low‘ | sed ‘s/\"//g‘ `
fx3=`echo $json | jq ‘.data.forecast[2].fx‘ | sed ‘s/\"//g‘ `
fl3=`echo $json | jq ‘.data.forecast[2].fl‘ | sed ‘s/\"//g‘ `
type3=`echo $json | jq ‘.data.forecast[2].type‘ | sed ‘s/\"//g‘ `
notice3=`echo $json | jq ‘.data.forecast[2].notice‘ | sed ‘s/\"//g‘ `
high4=`echo $json | jq ‘.data.forecast[3].high‘ | sed ‘s/\"//g‘ `
low4=`echo $json | jq ‘.data.forecast[3].low‘ | sed ‘s/\"//g‘ `
fx4=`echo $json | jq ‘.data.forecast[3].fx‘ | sed ‘s/\"//g‘ `
fl4=`echo $json | jq ‘.data.forecast[3].fl‘ | sed ‘s/\"//g‘ `
type4=`echo $json | jq ‘.data.forecast[3].type‘ | sed ‘s/\"//g‘ `
notice4=`echo $json | jq ‘.data.forecast[3].notice‘ | sed ‘s/\"//g‘ `
date "+当前时间为: %Y-%m-%d %H:%M:%S %A"
echo ‘您现在在‘$city‘,当前气温‘$wendu‘度,湿度‘$shidu‘,空气质量‘$quality‘,‘$ganmao‘。‘
echo ‘今天天气‘$type‘,最‘$high‘,最‘$low‘,‘$fx‘,风力‘$fl‘,‘$notice‘。‘
echo ‘明天天气‘$type2‘,最‘$high2‘,最‘$low2‘,‘$fx2‘,风力‘$fl2‘,‘$notice2‘。‘
echo ‘后天天气‘$type3‘,最‘$high3‘,最‘$low3‘,‘$fx3‘,风力‘$fl3‘,‘$notice3‘。‘
echo ‘大后天天气‘$type4‘,最‘$high4‘,最‘$low4‘,‘$fx4‘,风力‘$fl4‘,‘$notice4‘。‘
echo ‘--------------------------------------------------------------------------------------------------------‘
[sqoop@uhadoop-mzwc2w-task3 weather]$ sh weather.sh
--------------------------------------------------------------------------------------------------------
当前时间为: 2020-05-13 15:36:35 Wednesday
您现在在上海市,当前气温26度,湿度24%,空气质量良,极少数敏感人群应减少户外活动。
今天天气阴,最高温 22℃,最低温 18℃,东南风,风力3-4级,不要被阴云遮挡住好心情。
明天天气阴,最高温 22℃,最低温 19℃,东南风,风力3-4级,不要被阴云遮挡住好心情。
后天天气小雨,最高温 20℃,最低温 17℃,东风,风力4-5级,雨虽小,注意保暖别感冒。
大后天天气多云,最高温 24℃,最低温 18℃,东北风,风力<3级,阴晴之间,谨防紫外线侵扰。
--------------------------------------------------------------------------------------------------------
最后,我们可以调用微信的api,每天定时给自己的男/女朋友 朋友发天气预报的提醒
参考链接:linux登录终端时执行shell脚本显示天气预报 https://blog.csdn.net/qq_33595128/article/details/90701470
http://www.3gcomet.com/中国天气网的城市代码/
标签:cas net tps ash inux 今天 script pool 朋友
原文地址:https://blog.51cto.com/12445535/2494919