2015-04-13 20:58:32 +00:00
|
|
|
#!/usr/bin/env python3
|
2015-04-12 23:58:32 +00:00
|
|
|
|
2015-04-13 00:14:34 +00:00
|
|
|
print "This script is not working yet... If you are trying to test it, please delete lines 3 to 5 of this file."
|
|
|
|
import sys
|
|
|
|
sys.exit(0)
|
|
|
|
|
2015-04-12 23:58:32 +00:00
|
|
|
import sqlite3, csv
|
|
|
|
|
|
|
|
try:
|
|
|
|
infile = open('tweets.csv')
|
|
|
|
except IOError:
|
2015-04-13 20:58:32 +00:00
|
|
|
print("Please make sure that the tweets.csv from the Twitter download is located in this directory.")
|
2015-04-12 23:58:32 +00:00
|
|
|
|
|
|
|
input = csv.reader(infile)
|
|
|
|
|
|
|
|
conn = sqlite3.connect('Database.db')
|
|
|
|
cur = conn.cursor()
|
|
|
|
|
|
|
|
try:
|
|
|
|
cur.execute("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));")
|
|
|
|
except sqlite3.OperationalError:
|
2015-04-13 20:58:32 +00:00
|
|
|
print("Database.db already exists. Please delete it before trying to create a new one.")
|
2015-04-12 23:58:32 +00:00
|
|
|
|
|
|
|
for row in input[1:]:
|
2015-04-13 00:14:34 +00:00
|
|
|
cur.execute("INSERT INTO tweets VALUES(?,?,?,?,?,?,?,?,?,?);",row)
|