Skip to content

Instantly share code, notes, and snippets.

@MBalazs90
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MBalazs90/10008212 to your computer and use it in GitHub Desktop.
Save MBalazs90/10008212 to your computer and use it in GitHub Desktop.
Idojaras V1.0
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