Update makedb.py
This commit is contained in:
parent
305eed1519
commit
f23bc8dce7
30
makedb.py
30
makedb.py
|
@ -3,18 +3,20 @@
|
|||
|
||||
import os, sqlite3, sys
|
||||
|
||||
try:
|
||||
file = sys.argv[1]
|
||||
except IndexError:
|
||||
file = "Database.db"
|
||||
def makeDB(path="Database.db"):
|
||||
if os.path.isfile(path):
|
||||
raise IOError(path + " already exists. If you want to recreate it, please delete it first, or provide a different file name.")
|
||||
|
||||
if os.path.isfile(file):
|
||||
os.remove(file)
|
||||
|
||||
conn = sqlite3.connect(file)
|
||||
curs = conn.cursor()
|
||||
|
||||
curs.execute("CREATE TABLE tweets(tweet_id numeric, timestamp text, text text);")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
conn = sqlite3.connect(path)
|
||||
cur = conn.cursor()
|
||||
|
||||
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));")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
makeDB(sys.argv[1])
|
||||
except IndexError:
|
||||
makeDB()
|
||||
|
|
Loading…
Reference in a new issue