-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
85 lines (70 loc) · 2.32 KB
/
app.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
from flask import *
from flask_cors import CORS
from pymongo import MongoClient
from datetime import datetime
app = Flask(__name__)
CORS(app)
client = MongoClient('mongodb://localhost:27017')
db = client['csv_data']
collection = db['class_register']
# @app.route('/')
# def index():
# return send_from_directory('src/routes','+page.svelte')
@app.route('/api/data', methods=['GET'])
def get_data():
result = []
cursor = collection.find({})
for doc in cursor:
result.append({
'first_name': doc['first_name'],
'last_name': doc['last_name'],
'company_name': doc['company_name'],
'address': doc['address'],
'city': doc['city'],
'county': doc['county'],
'state': doc['state'],
'zip': doc['zip'],
'phone1': doc['phone1'],
'phone2': doc['phone2'],
'email': doc['email'],
'web': doc['web'],
'date': doc.get('date','')
})
return jsonify(result)
@app.route('/api/filtered-data', methods=['GET'])
def get_filtered_data():
start_date = request.args.get('start_date')
end_date = request.args.get('end_date')
# start_date = request.args.get('startDate')
# end_date = request.args.get('endDate')
query = {}
if start_date and end_date:
start_datetime = datetime.strptime(start_date, '%d-%m-%Y %H:%M:%S')
end_datetime = datetime.strptime(end_date, '%d-%m-%Y %H:%M:%S')
query = {
'date': {
'$gte': start_datetime,
'$lte': end_datetime
}
}
result = []
cursor = collection.find(query)
for doc in cursor:
result.append({
'first_name': doc['first_name'],
'last_name': doc['last_name'],
'company_name': doc['company_name'],
'address': doc['address'],
'city': doc['city'],
'county': doc['county'],
'state': doc['state'],
'zip': doc['zip'],
'phone1': doc['phone1'],
'phone2': doc['phone2'],
'email': doc['email'],
'web': doc['web'],
'date': doc.get('date','')
})
return jsonify(result)
if __name__ == '__main__':
app.run(debug = True)