Springboardmen commited on
Commit
fd35642
·
verified ·
1 Parent(s): c26e94a

Update database.py

Browse files
Files changed (1) hide show
  1. database.py +49 -2
database.py CHANGED
@@ -1,4 +1,5 @@
1
  import sqlite3
 
2
 
3
 
4
  # ---------------- DB CONNECTION ----------------
@@ -7,12 +8,13 @@ def get_connection():
7
  return conn
8
 
9
 
10
- # ---------------- CREATE TABLE ----------------
11
  def create_tables():
12
 
13
  conn = get_connection()
14
  cur = conn.cursor()
15
 
 
16
  cur.execute("""
17
  CREATE TABLE IF NOT EXISTS users(
18
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -22,6 +24,16 @@ def create_tables():
22
  )
23
  """)
24
 
 
 
 
 
 
 
 
 
 
 
25
  conn.commit()
26
  conn.close()
27
 
@@ -95,4 +107,39 @@ def verify_otp_db(email, otp):
95
 
96
  conn.close()
97
 
98
- return user
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import sqlite3
2
+ from datetime import date
3
 
4
 
5
  # ---------------- DB CONNECTION ----------------
 
8
  return conn
9
 
10
 
11
+ # ---------------- CREATE TABLES ----------------
12
  def create_tables():
13
 
14
  conn = get_connection()
15
  cur = conn.cursor()
16
 
17
+ # users table
18
  cur.execute("""
19
  CREATE TABLE IF NOT EXISTS users(
20
  id INTEGER PRIMARY KEY AUTOINCREMENT,
 
24
  )
25
  """)
26
 
27
+ # weight tracking table
28
+ cur.execute("""
29
+ CREATE TABLE IF NOT EXISTS weight_history(
30
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
31
+ email TEXT,
32
+ date TEXT,
33
+ weight REAL
34
+ )
35
+ """)
36
+
37
  conn.commit()
38
  conn.close()
39
 
 
107
 
108
  conn.close()
109
 
110
+ return user
111
+
112
+
113
+ # ---------------- SAVE WEIGHT ----------------
114
+ def save_weight(email, weight):
115
+
116
+ today = str(date.today())
117
+
118
+ conn = get_connection()
119
+ cur = conn.cursor()
120
+
121
+ cur.execute(
122
+ "INSERT INTO weight_history(email,date,weight) VALUES (?,?,?)",
123
+ (email, today, weight)
124
+ )
125
+
126
+ conn.commit()
127
+ conn.close()
128
+
129
+
130
+ # ---------------- GET WEIGHT HISTORY ----------------
131
+ def get_weight_history(email):
132
+
133
+ conn = get_connection()
134
+ cur = conn.cursor()
135
+
136
+ cur.execute(
137
+ "SELECT date, weight FROM weight_history WHERE email=?",
138
+ (email,)
139
+ )
140
+
141
+ data = cur.fetchall()
142
+
143
+ conn.close()
144
+
145
+ return data