在樹莓派中使用網路API
阿新 • • 發佈:2018-11-01
#!/usr/bin/env bash
LOCATION=guangzhou
TOKEN=***************************** //和風天氣key
WEATHER=$(curl "https://free-api.heweather.com/s6/weather?location=${LOCATION}&key=${TOKEN}")
SUGGESTIONS=$(echo ${WEATHER} | jq -r '.HeWeather6[0].lifestyle | values[].txt' )
echo ${WEATHER} > weather.txt
echo "Location:" `cat weather.txt | jq -r '.HeWeather6[0].basic.location'`
echo "Time:" `cat weather.txt | jq -r '.HeWeather6[0].update.loc'`
echo "Temperature:" `cat weather.txt | jq -r '.HeWeather6[0].now.tmp'`
echo ${SUGGESTIONS}
******************************
1.和風天氣 www.heweather.com -------->>>>>註冊帳號與得到認證key
2.jq : Linux下json的命令列工具 --------->>>>>jq 的應用
http://blog.chinaunix.net/uid-24774106-id-3830242.html