-
Notifications
You must be signed in to change notification settings - Fork 1
/
try.py
175 lines (104 loc) · 4.19 KB
/
try.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import mysql.connector
from flask import Flask, render_template, request
import json
from datetime import datetime
from scipy.misc import imread, imresize, imsave
import numpy as np
import re
import sys
import base64
import os
#Path to saved model
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
config = {
'user': 'root',
'password': 'sergiocas',
'host': 'localhost',
'database': 'project'
}
db = mysql.connector.connect(**config)
cursor = db.cursor()
def add_log(username, email, password, currentweight, goalweight, gender, dateofbirth):
sql = ("INSERT INTO users(username, email, password, current_weight, goal_weight, gender, dateofbirth) VALUES (%s, %s, %s, %s, %s, %s, %s)")
cursor.execute(sql, (username,email, password, currentweight, goalweight, gender, dateofbirth,))
db.commit()
def add_diary(username, food, serving, calories, date):
sql = ("INSERT INTO diary(username, food, serving, calories, date) VALUES (%s, %s, %s, %s, %s)")
cursor.execute(sql, (username,food, serving, calories, date,))
db.commit()
@app.route('/submit2', methods=['POST'])
def submit2():
if request.method == 'POST':
return render_template('registration.html')
@app.route('/submit', methods=['POST'])
def submit():
if request.method == 'POST':
username= request.form['username']
email= request.form['email']
password= request.form['password']
currentweight= request.form['current_weight']
goalweight= request.form['goal_weight']
gender = request.form['gender']
dateofbirth = request.form['month'] + " " + request.form['day'] + " " + request.form['year']
submit.username =username
result = submit.username
sql = """SELECT food FROM diary WHERE username = '%s'""" % (submit.username)
cursor.execute(sql)
food = cursor.fetchall()
sql = """SELECT calories FROM diary WHERE username = '%s'""" % (submit.username)
cursor.execute(sql)
calories = cursor.fetchall()
name =[]
name =calories
add_log(username,email, password, currentweight, goalweight, gender, dateofbirth)
return render_template('account2.html', result= result , food =food, calories =name, l1=len(food), l2=len(calories))
@app.route('/submit3', methods=['POST'])
def submit3():
if request.method == 'POST':
cursor.execute("SELECT * FROM users")
#result = cursor.fetchall()
return render_template('index.html', result=submit.username, flash="True")
@app.route('/logout', methods=['POST'])
def logout():
if request.method == 'POST':
return render_template('index.html')
@app.route('/UserInfo/<string:a>/<string:b>', methods=['POST'])
def processUserInfo(a,b):
username = submit.username
food = json.loads(a)
calories= json.loads(b)
serving = "1 serving"
date= datetime.now()
add_diary(username,food, serving, calories, date)
return 'Info recieved successfully'
@app.route('/submit4', methods=['POST'])
def submit4():
if request.method == 'POST':
username= request.form['username']
#password= request.form['password']
submit.username =username
result = submit.username
cursor.execute("SELECT username FROM diary;")
user = cursor.fetchall()
found ="false"
for x in user:
if x[0] == submit.username:
found = "true"
sql = """SELECT food FROM diary WHERE username = '%s'""" % (submit.username)
cursor.execute(sql)
food = cursor.fetchall()
sql = """SELECT calories FROM diary WHERE username = '%s'""" % (submit.username)
cursor.execute(sql)
calories = cursor.fetchall()
name =[]
name =calories
if found == "true":
return render_template('account2.html', result= result , food =food, calories =name, l1=len(food), l2=len(calories), found=found)
else:
return render_template('index.html', found=found)
if(__name__) == '__main__':
app.debug = True
app.run()