Last active
January 5, 2016 07:22
-
-
Save mshr-h/0efeb32285cc82221aec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
key = "fdksaljvdispoajhp89vdsa8sFDSpvdsa" | |
def flightsearch(origin, destination, depart_data): | |
url = "https://www.googleapis.com/qpxExpress/v1/trips/search?key=%s" % key | |
code = { | |
"request": { | |
"passengers": { | |
"kind": "qpxexpress#passengerCounts", | |
"adultCount": 1, | |
}, | |
"slice": [ | |
{ | |
"kind": "qpxexpress#sliceInput", | |
"origin": origin, # "LGA" | |
"destination": destination, # "MIA" | |
"date": depart_data, # "2015-06-09" | |
} | |
], | |
"refundable": "false", | |
"solutions": 20 | |
} | |
} | |
jsonreq = json.dumps(code, encoding='utf-8') | |
req = urllib2.Request(url, jsonreq, {'Content-Type': 'application/json'}) | |
flight = urllib2.urlopen(req) | |
response = flight.read() | |
flight.close() | |
return response | |
def flightsearchresults(origin, destination, depart_data): | |
flight = [] | |
# read json data from file | |
j = json.load(file('%s-%s.json' % (origin, destination))) | |
# j = flightsearch(origin, destination, depart_data) | |
for t in j['trips']['tripOption']: | |
price = float(t['saleTotal'][3:]) | |
depart = t['slice'][0]['segment'][0]['leg'][0]['departureTime'][11:16] | |
arrive = t['slice'][0]['segment'][-1]['leg'][0]['arrivalTime'][11:16] | |
origin = t['slice'][0]['segment'][0]['leg'][0]['origin'] | |
dest = t['slice'][0]['segment'][-1]['leg'][0]['destination'] | |
flight.append((depart, arrive, int(price))) | |
return flight | |
def createschedule(people, dest, dep, ret): | |
flights = {} | |
for p in people: | |
name, origin = p | |
flights[(origin, dest)] = flightsearchresults(origin, dest, dep) | |
flights[(dest, origin)] = flightsearchresults(dest, origin, ret) | |
return flights |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment