-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_db.py
More file actions
49 lines (43 loc) · 1.15 KB
/
create_db.py
File metadata and controls
49 lines (43 loc) · 1.15 KB
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
conn = sqlite3.connect("bot.db")
cursor = conn.cursor()
sqlcommands: dict = {
# user
"User": """CREATE TABLE User (
id INTEGER PRIMARY KEY AUTOINCREMENT,
chat_id INTEGER NOT NULL UNIQUE
);""",
# temperature
"Temperature": """CREATE TABLE Temperature (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value REAL NOT NULL,
date DATETIME NOT NULL
);""",
# humidity
"Humidity": """CREATE TABLE Humidity (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value REAL NOT NULL,
date DATETIME NOT NULL
);""",
# daily averages
"Daily_Avergages": """CREATE TABLE Daily_Averages (
id INTEGER PRIMARY KEY AUTOINCREMENT,
avg_temperature REAL NOT NULL,
avg_humidity REAL NOT NULL,
date DATE NOT NULL UNIQUE
);""",
"Weekly_Averages": """CREATE TABLE Weekly_Averages(
id INTEGER PRIMARY KEY AUTOINCREMENT,
avg_temperature REAL NOT NULL,
avg_humidity REAL NOT NULL,
date DATETIME NOT NULL
)"""
}
for command in sqlcommands:
try:
cursor.execute(sqlcommands[command])
print(f"Creating {command}")
except Exception:
print(f"{command} is already created")
conn.commit()
conn.close()