-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathindex.py
More file actions
119 lines (100 loc) · 2.63 KB
/
index.py
File metadata and controls
119 lines (100 loc) · 2.63 KB
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
import datetime
import time
import requests
from flask import Flask, jsonify
import json
import populartimes
import googlemaps
import os
API_KEY = os.getenv("API_KEY")
#app instance
app = Flask(__name__)
@app.route("/api/python")
def hello_world():
return "<p>Hello, World!</p>"
@app.route("/api/popular_times_demo", methods=['GET'])
def delayed_api_req():
time.sleep(20)
response = [
{
"coordinates": {
"lat": 12.9682704,
"lng": 74.8065197
},
"weekly_sum": 5307
},
{
"coordinates": {
"lat": 12.9883174,
"lng": 74.8005921
},
"weekly_sum": 3800
},
{
"coordinates": {
"lat": 13.0223759,
"lng": 74.8079575
},
"weekly_sum": 5655
},
{
"coordinates": {
"lat": 12.9894559,
"lng": 74.8015439
},
"weekly_sum": 3798
},
{
"coordinates": {
"lat": 12.9743232,
"lng": 74.8036651
},
"weekly_sum": 4279
},
{
"coordinates": {
"lat": 12.9815466,
"lng": 74.8227607
},
"weekly_sum": 4314
},
{
"coordinates": {
"lat": 13.0010366,
"lng": 74.8260901
},
"weekly_sum": 5191
}
]
return response
@app.route("/api/popular_times_test", methods=['GET'])
def weight_gen():
weights = []
pop_time = popular_times()
for index in range(len(pop_time)):
pop_time_temp = pop_time[index]
weight = {
"coordinates": pop_time_temp["coordinates"],
"weekly_sum": 0
}
for day_data in pop_time_temp["populartimes"]:
data_values = day_data["data"]
day_sum = sum(data_values)
weight["weekly_sum"] += day_sum
weights.append(weight)
return jsonify(weights)
def popular_times():
[p1, p2] = geocode()
response = populartimes.get(API_KEY, ["bar"], p1, p2)
return response
def geocode():
gmaps = googlemaps.Client(key=API_KEY)
geocode_response = gmaps.geocode(address="Surathkal")
geocode_response_dict = geocode_response[0]
northeast = geocode_response_dict["geometry"]["bounds"]["northeast"]
southwest = geocode_response_dict["geometry"]["bounds"]["southwest"]
p1 = (southwest["lat"], southwest["lng"])
p2 = (northeast["lat"], northeast["lng"])
return [p1, p2]
if __name__ == "__main__":
app.run(debug=True)