1

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 =)

okonik
  • 115
  • 1
  • 3
  • 10
  • Check out https://coderwall.com/p/gc1vpq. It does exactly what you want if you don't mind getting an API key for Wunderground. Translating the PHP code to Python should be easy enough. – nwk Feb 27 '14 at 23:29

1 Answers1

3

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/

endolith
  • 25,479
  • 34
  • 128
  • 192
wbt11a
  • 798
  • 4
  • 12
  • Nice. I like it. A powerfull thing. I'm just not sure in sended temp data. For example: New-York town from USA has many WOEID. I don't know how to determine the correctly for my IP. Need thinking about. Anyway it would work perfectly for me if I'll bind WOEID by myself. – okonik Feb 28 '14 at 00:23
  • I'm glad I could help you. I learned a bit myself! Anyway, I checked SO and there was a similar question on calculating WOEID. Please see http://stackoverflow.com/questions/2093358/receive-a-woeid-by-lat-long-with-yahoos-api It appears yahoo has provided the means to do so already. – wbt11a Feb 28 '14 at 00:32