Fix makedb bug introduced in 19ae6e4a
This commit is contained in:
parent
a1d0c7fd97
commit
5325d064da
|
@ -6,17 +6,16 @@ import tools
|
|||
import sys
|
||||
|
||||
def makeDB(path=tools.config.dbpath):
|
||||
if tools.fileExists(path):
|
||||
raise IOError(path + " already exists. If you want to recreate it, please delete it first, or provide a different file name.")
|
||||
db = tools.dbHelper(path, create = True)
|
||||
|
||||
db = tools.dbObject(path)
|
||||
|
||||
db.executeQuery("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));")
|
||||
|
||||
db.commit()
|
||||
db.closeConnection()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 2:
|
||||
raise ValueError(sys.argv[0] + " only takes one argument, the path of the new database file.")
|
||||
try:
|
||||
makeDB(sys.argv[1])
|
||||
except IndexError:
|
||||
|
|
10
tools.py
10
tools.py
|
@ -31,15 +31,17 @@ class dbObject:
|
|||
return False
|
||||
|
||||
|
||||
def dbCheck(db):
|
||||
if dbInitialized(db):
|
||||
def dbCheck(db, create = False):
|
||||
if (!create and dbInitialized(db)) or (create and !dbInitialized(db)):
|
||||
return True
|
||||
if create:
|
||||
raise ValueError("Provided database file " + path + " is already initialized. Remove it manually before trying to recreate it.")
|
||||
raise ValueError("Provided database file " + path + " is not initialized. Create it using makedb.py or csvdb.py")
|
||||
|
||||
|
||||
def dbHelper(path):
|
||||
def dbHelper(path, create = False):
|
||||
db = dbObject(path)
|
||||
dbCheck(db)
|
||||
dbCheck(db, create)
|
||||
return db
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue