This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo.py
executable file
·61 lines (40 loc) · 1.71 KB
/
geo.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
#!/usr/bin/python
import requests
import sys
from scipy.interpolate import interp1d
from envVariables import API_KEY
def main():
i, j = 0, 0
# cust id -> account(s) id -> purchase(s) id -> merchant id -> gps
# custId = "59f45071a73e4942cdafe49f" # Non Local
# custId = "59f45070a73e4942cdafe49e" # Local
if len(sys.argv) != 2:
exit("Error: Must pass customer id as first and only arguemnt")
custId = sys.argv[1]
file = open("capital_one_open_bank/static/GeoJSONP.js", "w")
file.write('eqfeed_callback({"type": "FeatureCollection","features": [')
r = requests.get("http://api.reimaginebanking.com/customers/" + custId + "/accounts?key=" + API_KEY)
try:
# Loop though all the customers accounts
while r.json()[i]['_id'] != "":
s = requests.get("http://api.reimaginebanking.com/accounts/" + str(r.json()[i]['_id']) + "/purchases?key=" + API_KEY)
# Loop though all the purchases in this account
while s.json()[j]['merchant_id'] != "":
t = requests.get("http://api.reimaginebanking.com/merchants/" + str(s.json()[j]['merchant_id']) + "?key=" + API_KEY)
file.write('{"type": "Feature","properties": {"mag": ' + str(calcMag(s.json()[j]["amount"])) + '}, "geometry": {"type": "Point","coordinates": [' + str(t.json()["geocode"]["lng"]) + ', ' + str(t.json()["geocode"]["lat"]) + ']}},\n')
j += 1
i += 1
except IndexError:
pass
file.write(']});')
file.close()
def calcMag(money):
if money > 512:
money = 511
elif money < 0:
money = 0
m = interp1d([0, 512], [3, 6])
return m(money)
pass
if __name__ == "__main__":
main()