-
Notifications
You must be signed in to change notification settings - Fork 31
/
setup.py
49 lines (40 loc) · 1.45 KB
/
setup.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
47
48
49
import sqlite3
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file)
return conn
except Exception as e:
print(e)
return None
def execute(conn, sql):
try:
c = conn.cursor()
c.execute(sql)
conn.commit()
c.close()
except Exception as e:
print(e)
database = "properties.db"
sql_create_properties_table = """ CREATE TABLE IF NOT EXISTS properties (
id integer PRIMARY KEY,
internal_id text NOT NULL,
provider text NOT NULL,
url text NOT NULL,
captured_date integer DEFAULT CURRENT_TIMESTAMP
); """
sql_create_index_on_properties_table = """ CREATE INDEX properties_internal_provider ON properties (internal_id, provider); """
# create a database connection
conn = create_connection(database)
with conn:
if conn is not None:
# create properties table
execute(conn, sql_create_properties_table)
# create properties indexes
execute(conn, sql_create_index_on_properties_table)
else:
print("Error! cannot create the database connection.")