문제

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:

  1. Interface with http://weather.yahooapis.com/forecastrss?w=2442047&u=f where w= is your WOEID
  2. Parse XML using available python libraries
  3. Display desired output

Or (BASH):

  1. Download the xml through bash (wget)
  2. Use grep/awk/sed to extract desired information
  3. 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/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top