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)
22 data = json.loads(raw_data)
24 # interate through the data from the json website and create a list of
25 # data we want to store
27 entries = data['places']
28 # interate through the list of things and import it
30 joke_id = entry['entries'][0]['id']
31 joke = entry['entries'][0]['text']
32 (coord_lat, coord_long) = entry['location']['point']
33 location = entry['location']['name']
34 url = "http://shewentofherownaccord.com/joke/%s" % joke_id
36 place_values = (joke_id, joke, coord_lat, coord_long, location, url)
37 places.append(place_values)
40 # try to connect to the database and make sure that things work
43 con = lite.connect('swohoa.db')
46 cur.execute('SELECT SQLITE_VERSION()')
48 print "SQLite version: %s" % data
51 print "Error %s:" % e.args[0]
55 cur.execute("DROP TABLE IF EXISTS jokes")
56 cur.execute("CREATE TABLE jokes(id INT, joke TEXT, lat FLOAT, long FLOAT, location TEXT, url TEXT)")
58 cur.executemany("INSERT INTO jokes VALUES(?, ?, ?, ?, ?, ?)", places)