在树莓派中使用网络API

#!/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

  

 

posted @ 2018-11-01 16:03  orange_gz  阅读(752)  评论(0编辑  收藏  举报