-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFI.py~
executable file
·115 lines (109 loc) · 3.3 KB
/
CFI.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
from flask import Flask,render_template
<<<<<<< HEAD
import pyqrcode,json
from flask import jsonify, request
=======
import json
from flask import jsonify
>>>>>>> 86185c1839ecdd153cc108fa36069edf8fb1abd5
import random,string
from pymongo import MongoClient
import pymongo
import random
import requests
application = Flask(__name__)
@application.route('/login',methods=['POST'])
def login():
aadhaarID = request.json['id']
password = request.json['password']
cfiClient = MongoClient()
#analyticsClient = MongoClient()
cfiDB = cfiClient['cfi']
userCollection = cfiDB['user']
query = dict()
query['aadhaarID'] = aadhaarID
userObject = userCollection.find_one(query)
if not userObject :
response = dict()
response['status'] = "User Not found"
return jsonify(response),403
else:
if password == userObject['password']:
response = dict()
response['userName'] = userObject['userName']
response['aadhaarID'] = aadhaarID
response['gender'] = userObject['gender']
response['status'] = "Success"
return jsonify(response),200
else:
response = dict()
response['status'] = "Password Invalid"
return jsonify(response),403
@application.route('/monumentslist',methods=['GET'])
def monumentsList():
response = list()
cfiClient = MongoClient()
#analyticsClient = MongoClient()
cfiDB = cfiClient['cfi']
monumentCollection = cfiDB['monuments']
monumentCursor = monumentCollection.find()
for monumentObject in monumentCursor:
entry = dict()
entry['photo'] = monumentObject['photoURL']
entry['name'] = monumentObject['monumentName']
entry['id'] = monumentObject['monumentId']
response.append(monumentObject)
return jsonify(response), 200
@application.route('/booking',methods=['POST'])
def booking():
dbObject = dict()
dbObject['userID'] = request.json['userId']
visitorList = list()
visitors = request.json['visitors']
response = dict()
cfiClient = MongoClient()
#analyticsClient = MongoClient()
cfiDB = cfiClient['cfi']
userCollection = cfiDB['user']
responseList = list()
dbList = list()
for entry in visitors :
userId = entry['id']
query = dict()
query["aadhaarID"] = userID
userObject = userCollection.find_one(query)
responseEntry = dict()
dbEntry = dict()
if not userID :
responseEntry[userID] = "false"
else :
if entry['userName'] == userObject['userName']:
responseEntry[userID] = "true"
dbEntry['userID'] = userID
dbEntry['userName'] = entry['userName']
dbList.append(dbEntry)
else :
responseEntry[userID] = "false"
responseList.append(responseEntry)
dbObject['visitors'] = responseList
response['status'] = responseList
ticketID = 'GOV - ' + str(random.getrandbits(6))
response['ticketID'] = ticketID
dbObject['ticketID'] = ticketID
#query = dict()
#query['aadhaarID'] = request.json['userId']
#userObject = userCollection.findOne(query)
#label =
QRcodebase64string = callFunction(ticketID)
response['QRcode'] = QRcodebase64string
dbObject['QRcode'] = QRcodebase64string
cfiClient = MongoClient()
#analyticsClient = MongoClient()
cfiDB = cfiClient['cfi']
dbObject['monumentName'] = request.json['monumentName']
monumentCollection = cfiDB['tickets']
monumentsCollection.insert_one(dbObject)
return jsonify(response), 200
if __name__ == '__main__':
application.debug = True
application.run(host = '0.0.0.0')