-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntitled8.py
143 lines (126 loc) · 4.96 KB
/
untitled8.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
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 15 17:12:08 2021
@author: HI
"""
#calender screen
@token_required
def calender():
if request.is_json:
print("here")
token = request.headers.get('Authorization')
if not token:
return jsonify("Invalid token")
data = jwt.decode(token, JWT_SECRET)
print(data['date'])
# email = request.get_json()['email']
date = data['date']
#mobile_number = data['mobile_number']
# print(data)
date_collection = mongo.db.log
user = date_collection.find_one({"date":date})
if(user):
workouts = date_collection.find_one({"workouts":workouts})
diet = date_collection.find_one({"diet":diet})
return workouts
return diet
#return make_response(jsonify({"message":to_json(user)}),200)
else:
return make_response(jsonify({"message":"user does not exist"}),200)
else:
return make_response(jsonify({"message":"bad request"}),401)
@user.route("/dietplan",methods=["POST"])
@token_required
def dietplan():
token = request.form["Authorization"]
inp = request.form
data = jwt.decode(token, JWT_SECRET)
mealplan = data["mealplan"]
col=mongo.db.test1
meal=col.find_one({"mealplan":mealplan,"calories":calories,"time":time,"mealdetails":mealdetails})
if(meal):
print(meal)
return make_response(jsonify({"message":to_json(meal)}),200)
else:
return make_response(jsonify({"message":"meal chart does not exist"}),200)
#new meal addition form by the user
@user.route("/dietplan",methods=["POST"])
def addmeal():
db=client.meal_user_added
print(request.form)
meal={"Date":request.form.get("date"),
"Meal type":request.form.get("Meal type"),
"Meal name":request.form.get("Meal name"),
"Total servings":request.form.get("Total servings"),
"Calories":request.form.get("Calories"),
"Total nutrients":request.form.get("Total nutrients")
}
if db.users.find_one({"Meal type": meal['Meal type']}):
return jsonify({"error":"Meal type already exists"}),400
#adding to meal record to the database
if db.users.insert_one(meal):
return jsonify(meal),200
return jsonify({"error":"Adding meal failed"}),400
@user.route("/activity",methods=["POST"])
def activity():
if request.is_json:
print("here")
token = request.headers.get('Authorization')
if not token:
return jsonify("Invalid token")
data = jwt.decode(token, JWT_SECRET)
print(data['date'])
# email = request.get_json()['email']
date = data['date']
# print(data)
date_collection = mongo.db.activityWorkout
user = date_collection.find_one({"date":date})
if(user):
activites = date_collection.find_one({"activity":activity})
return activites
#return make_response(jsonify({"message":to_json(user)}),200)
else:
return make_response(jsonify({"message":"user does not exist"}),200)
else:
return make_response(jsonify({"message":"bad request"}),401)
@user.route("/workout",methods=["POST"])
def workout():
if request.is_json:
print("here")
token = request.headers.get('Authorization')
if not token:
return jsonify("Invalid token")
data = jwt.decode(token, JWT_SECRET)
print(data['date'])
# email = request.get_json()['email']
date = data['date']
# print(data)
date_collection = mongo.db.activityWorkout
user = date_collection.find_one({"date":date})
if(user):
workouts = date_collection.find_one({"workouts":workouts})
return workouts
#return make_response(jsonify({"message":to_json(user)}),200)
else:
return make_response(jsonify({"message":"user does not exist"}),200)
else:
return make_response(jsonify({"message":"bad request"}),401)
#insights screen
#@token_required
#@valid_response
#def insights():
# token = request.headers.get('Authorization')
# print(token)
# tokendata = jwt.decode(token,JWT_SECRET)
# user_collection = mongo.db.users
# req = request.get_json()
# user = user_collection.find_one({"email":tokendata['email']})
# if(user):
# try:
# user['user_mode']=req['user_mode']
# user_collection.save(user)
# except:
# return make_response(jsonify({"message":"Could not change the status of the user"}),401)
# else:
# return make_response(jsonify({"message":"Not found"}),404)
# return make_response(jsonify({"message":"user mode changed"}),202)