-
Notifications
You must be signed in to change notification settings - Fork 1
/
reimburse.py
56 lines (41 loc) · 2.43 KB
/
reimburse.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
import config
import json
import googlemaps
from datetime import datetime
from pymongo import MongoClient
def find_distance(event, context):
client = MongoClient(config.DB_URI)
db = client['lcs-db']
db.authenticate(config.DB_USER,config.DB_PASS)
tests = db['test']
start_loc = tests.find_one({"email": event['email']}, {"address": 1, "city": 1, "state": 1, "zip": 1}) # will be called using email of pertinent user
start_loc = start_loc['address'] + ' ' + start_loc['city'] + ', ' + start_loc['state'] + ' ' + start_loc['zip']
gmaps = googlemaps.Client(key=config.maps_key)
values = {
'bus': {},
'train': {},
'car': {}
}
rac_address = config.hackru_location['address'] + ' ' + config.hackru_location['city'] + ', ' + config.hackru_location['state'] + ' ' + config.hackru_location['zip']
bus_values = gmaps.distance_matrix(
origins = start_loc['address'] + ' ' + start_loc['city'] + ', ' + start_loc['state'] + ' ' + start_loc['zip'],
destinations = rac_address,
units = 'imperial',
mode = 'transit',
transit_mode = 'bus')
values['bus'] = {'distance': bus_value['rows'][0]['elements'][0]['distance']['value'], 'reimbursement': config.bus_miles_reimburse* (bus_value['rows'][0]['elements'][0]['distance']['value'])}
train_values = gmaps.distance_matrix(
origins = start_loc['address'] + ' ' + start_loc['city'] + ', ' + start_loc['state'] + ' ' + start_loc['zip'],
destinations = rac_address,
units = 'imperial',
mode = 'transit',
transit_mode = 'train')
values['train'] = {'distance': train_values['rows'][0]['elements'][0]['distance']['value'], 'reimbursement': config.train_values_miles_reimburse* (bus_value['rows'][0]['elements'][0]['distance']['value'])}
car_values = gmaps.distance_matrix(
origins = start_loc['address'] + ' ' + start_loc['city'] + ', ' + start_loc['state'] + ' ' + start_loc['zip'],
destinations = rac_address,
units = 'imperial',
mode = 'driving',
traffic_model = 'best_guess')
values['car'] = {'distance': car_values['rows']['elements']['distance']['value'], 'reimbursement': car_values['rows'][0]['elements'][0]['distance']['value'] * config.car_miles_reimburse}
return {'statusCode': 200, 'body': json.dumps(values)}