Note that there are some explanatory texts on larger screens.

plurals
  1. POPython reading json file and placing into SQLlite
    primarykey
    data
    text
    <p>I am having two problems (at least) with the below code.</p> <p>My goal is to read in each tweets, parse a variable with JSON and place it into its own row in SQLlite. Of all the variables in the tweet, I am just want six of them.</p> <p>I am able to read in the tweets fine (and the DB and table are created without issue).</p> <p>1) I get an error with my create dictionary. It states "dictt not defined". (I had it working earlier, but did something for it not to work anymore).</p> <p>2) When dictt did work, only the first tweet would load. I want all the tweets to load. So there is a problem with that loop.</p> <p>Help on either?</p> <pre><code>#Created the DB import sqlite3 conn = sqlite3.connect('twitter.db') c = conn.cursor() #Created the table for the tweets c.execute("CREATE TABLE IF NOT EXISTS Tweet(created_at, id, text, source, in_reply_to_user_ID,retweet_Count)") import json import urllib2 #Read file and print a line webFD = urllib2.urlopen("http://rasinsrv07.cstcis.cti.depaul.edu/CSC455/assignment4.txt") tweets = webFD.readlines() #prints all tweets for tweet in tweets: print tweet #create dictionary try: dictt = json.loads(tweet) except ValueError: continue #print dictionary to verify print dictt.keys() #print values to verify print dictt.values() #to load all parsed tweets into sqlite for elt in tweets: currentRow = elt[:-1].split(", ") c.execute('INSERT INTO Tweet VALUES (?, ?, ?, ?, ?, ?)', (dictt['created_at'], dictt["id"], dictt["text"], dictt['source'], dictt['in_reply_to_user_id'], dictt['retweet_count'])) conn.commit() conn.close() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload