Skip to content

Instantly share code, notes, and snippets.

@IshamMohamed
Last active December 29, 2015 02:09
Show Gist options
  • Save IshamMohamed/7598915 to your computer and use it in GitHub Desktop.
Save IshamMohamed/7598915 to your computer and use it in GitHub Desktop.
Easy APIs Project (http://gcdc2013-easyapisproject.appspot.com/) Weather API implementation in Python
# -*- coding: utf-8 -*-
import urllib
import urllib2
def celsius(a):
responsex = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/unitconversion?q=' + urllib.quote(a + ' in celsius'))
html = responsex.read()
responsex.close()
html = html[1:] #remove first {
html = html[:-1] #remove last }
html = html.split('}{') #split and put each resutls to array
html = html[1].replace('°','')
return html
print "Enter a city name:",
q = raw_input() #get sity from user
response = urllib2.urlopen('http://gcdc2013-easyapisproject.appspot.com/weather?q='+urllib.quote(q))
html = response.read()
response.close()
html = html[1:] #remove first {
html = html[:-1] #remove last }
html = html.split('}{') #split and put each resutls to array
print "Today weather is " + html[1]
print "Temperature is " + celsius(html[3])
print "Humidity is " + html[9]
print "Pressure is " + html[11]
print "Wind speed is " + html[13]
print "Wind direction is " + html[15] +'('+html [17]+')'
print "Cloud type is " + html[19]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment