Python‎ > ‎

Retrieve JSON data from a Web Service

posted Sep 5, 2014, 12:06 AM by Chris G
Python is a great tool for retrieving and processing data. For instance, retrieving the sunset time from the web using the JSON Weather Underground API would only require a few lines of code:
import urllib, json
import datetime

url = "<your api code>/geolookup/conditions/astronomy/q/CA/fresno.json"
now =

response = urllib.urlopen(url);
data = json.loads(
sunSetTime = datetime.datetime(now.year, now.month,, int(data['sun_phase']['sunset']['hour']), int(data['sun_phase']['sunset']['minute']), 00)