How to get outdoors temperature on Bash?
-
24-12-2019 - |
문제
I need to write a script on bash and on python that will receive temperature from outdoors using geolocation methods.
I remind that when I actively used Ubuntu, I had a snippet or something like. It received from somewhere outdoor temperature, wind directrion, wind speed and etc.
I guess it would great for my script if exist some public API of this.
And I am sure SO community knows it. Share, please =)
해결책
Check out http://developer.yahoo.com/weather/
Your python script will probably:
- Interface with
http://weather.yahooapis.com/forecastrss?w=2442047&u=f
wherew=
is your WOEID - Parse XML using available python libraries
- Display desired output
Or (BASH):
- Download the xml through bash (
wget
) - Use
grep
/awk
/sed
to extract desired information - Display in terminal
*Edit:
just messed around with it in bash. This will extract the Temperature. Im sure you can clean it up.
#!/bin/bash
wget http://weather.yahooapis.com/forecastrss?w=2502265 -O test.xml > /dev/null 2>&1
TEMP=$(grep "yweather:condition" test.xml | cut -d"=" -f4 | cut -d"\"" -f2)
echo "Temperature: " $TEMP
rm -rf test.xml
Calculate your WOEID easily here: http://isithackday.com/geoplanet-explorer/
제휴하지 않습니다 StackOverflow