-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.py
executable file
·47 lines (39 loc) · 1017 Bytes
/
db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import yaml
import pdb
import time
import sqlite3
from sqlite3 import Error
class Db:
def __init__(self):
cfg = self.get_config()
self.db_file = cfg.get('db').get('location')
def get_connection(self):
try:
conn = sqlite3.connect(self.db_file)
return conn
except Error as e:
print(e)
return None
finally:
return None
def create_db(self):
try:
conn = sqlite3.connect(self.db_file)
try:
with open('.schema') as f:
c = conn.cursor()
c.execute(f.read())
except Error as e:
print(e)
except Error as e:
print(e)
finally:
conn.close()
def get_config(self):
with open("config.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
return cfg
if __name__ == '__main__':
db = Db()
db.create_db()