-
Notifications
You must be signed in to change notification settings - Fork 0
/
weights.py
34 lines (30 loc) · 1.2 KB
/
weights.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
from db import db
from flask import session
def add_weight(user_id, weight_now, date):
try:
sql = """INSERT INTO weights (user_id,weight_now,weight_date,created,modified,visible)
VALUES (:user_id,:weight_now,:weight_date,NOW(),NOW(),1)"""
db.session.execute(sql, {"user_id":user_id, "weight_now":weight_now, "weight_date":date})
db.session.commit()
except:
return False
return True
def get_last(user_id):
sql = "SELECT weight_now FROM weights WHERE user_id=:user_id ORDER BY weight_date DESC LIMIT 1"
result = db.session.execute(sql, {"user_id":user_id})
return result.fetchone()
def get_weights(user_id):
# try:
# print("Kokeillaan")
sql = "SELECT weight_date,weight_now FROM weights WHERE user_id=:user_id ORDER BY weight_date"
result = db.session.execute(sql, {"user_id":user_id})
return result.fetchall()
# except:
# return 0
def check_date(user_id, date):
sql = "SELECT 1 FROM weights WHERE user_id=:user_id AND weight_date=:weight_date AND visible=1"
result = db.session.execute(sql, {"user_id":user_id, "weight_date":date})
if result.fetchone() != None:
return True
else:
return False