twitools/makedb.py

23 lines
752 B
Python
Raw Normal View History

2015-04-13 20:58:32 +00:00
#!/usr/bin/env python3
2015-03-09 17:32:24 +00:00
# -*- coding: utf-8 -*-
import config, os, sqlite3, sys
2015-03-09 17:32:24 +00:00
def makeDB(path=config.dbpath):
2015-04-14 14:27:08 +00:00
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.")
2015-03-09 17:32:24 +00:00
2015-04-14 14:27:08 +00:00
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()