Create database if it doesn't exist

This commit is contained in:
dave 2014-08-30 17:55:59 -04:00
parent 2d0a2a9a0a
commit 6b3c08100d
1 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
import sqlite3
import os.path
class database:
def __init__(self):
@ -14,6 +15,12 @@ class database:
"""INSERT INTO "streams" ("id","user","name","url","directory","status","message") VALUES (NULL,NULL,'WCMF Breakroom','http://1681.live.streamtheworld.com/WCMFFMAAC','wcmf-breakroom','0','')""",
"""INSERT INTO "times" ("id","streamid","su","m","t","w","r","f","sa","starthour","startmin","endhour","endmin") VALUES (NULL,'1','0','1','1','1','1','1','0','2','0','7','15')"""
]
if not os.path.exists("db.sqlite"):
db = sqlite3.connect("db.sqlite", check_same_thread=False, cached_statements=0, isolation_level=None)
cursor = db.cursor()
for query in queries:
cursor.execute(query)
db.close()
def openDB(self):
db = sqlite3.connect("db.sqlite", check_same_thread=False, cached_statements=0, isolation_level=None)