9 from pprint import pprint
11 # download the raw data from the website
12 raw_data = urllib2.urlopen("http://shewentofherownaccord.com/mapfeed").read()
14 # fix some errors in the json
15 raw_data = raw_data.replace('\r\n', '')
16 raw_data = raw_data.replace('""', '"')
17 raw_data = re.sub(';$', '', raw_data)
19 data = json.loads(raw_data)
21 # interate through the data from the json website and create a list of
22 # data we want to store
24 entries = data['places']
25 # interate through the list of things and import it
27 joke_id = entry['entries'][0]['id']
28 joke = entry['entries'][0]['text']
29 (coord_lat, coord_long) = entry['location']['point']
30 location = entry['location']['name']
31 url = "http://shewentofherownaccord.com/joke/%s" % joke_id
33 place_values = (joke_id, joke, coord_lat, coord_long, location, url)
34 places.append(place_values)
37 # try to connect to the database and make sure that things work
40 con = lite.connect('swohoa.db')
43 cur.execute('SELECT SQLITE_VERSION()')
45 print "SQLite version: %s" % data
48 print "Error %s:" % e.args[0]
52 cur.execute("DROP TABLE IF EXISTS jokes")
53 cur.execute("CREATE TABLE jokes(id INT, joke TEXT, lat FLOAT, long FLOAT, location TEXT, url TEXT)")
55 cur.executemany("INSERT INTO jokes VALUES(?, ?, ?, ?, ?, ?)", places)