Last active
August 29, 2015 13:58
-
-
Save MBalazs90/10008212 to your computer and use it in GitHub Desktop.
Idojaras V1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION idojaras(lat float, lon float) | |
RETURNS float AS $$ | |
import sys | |
if sys.version_info[0] == 2: | |
from urllib2 import urlopen | |
else: # Python 3 | |
from urllib.request import urlopen | |
import json | |
def get_temp(lat, lon): | |
data = urlopen( | |
"http://api.openweathermap.org/data/2.5/find?lat=%s&lon=%s&cnt=1" | |
% (lat, lon)) | |
js_data = json.loads(data.read().decode('utf-8')) | |
try: | |
return js_data['list'][0]['main']['temp'] - 273.15 | |
except (KeyError, IndexError): | |
return None | |
return get_temp(lat, lon) | |
$$ LANGUAGE plpythonu; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment