-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp4.py
More file actions
136 lines (129 loc) · 3.85 KB
/
tmp4.py
File metadata and controls
136 lines (129 loc) · 3.85 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
##maxprice aur passengers abhi dekh lena
import json
import requests
url='https://www.googleapis.com/qpxExpress/v1/trips/search?key='
headers={'Content-Type': 'application/json'}
apikey='AIzaSyB0Z5xwCsHNYnkA1YSYFePn_qNOQ-R27MM'
url=url+apikey
####json request is of the form:
##{
## "request": {
## "passengers": {
## "adultCount": "1"
## },
## "slice": [
## {
## "origin": "SFO",
## "destination": "LAX",
## "date": "2014-09-19"
## }
## ],
## "solutions": "1"
## }
##}
origin_code=raw_input("enter orig code")
desti_code=raw_input("enter dest code")
date='2015-04-25'
sol=raw_input("no. of air solutions required")
ad=int(raw_input("no of adults"))
cd=0
sd=0
infl=0
infs=0
maxpr=raw_input("maximum price you can afford")
prelst=['COACH', 'PREMIUM_COACH', 'BUSINESS', 'FIRST']
print "available Cabins"
count=1
for ca in prelst:
print count,
print " "+ca
count+=1
prc=int(raw_input("enter preffered cabin"))
obj={
"request": {
"passengers": {
"adultCount": ad,
"childCount": cd,
"infantInLapCount": infl,
"infantInSeatCount": infs,
"seniorCount": sd,
},
"slice": [
{
"origin": origin_code,
"destination": desti_code,
"date": date,
"preferedCabin":prelst[prc-1]
}
],
"solutions": sol,
"maxprice": "INR-maxpr",
}
}
##request.maxprice vaale se max price tak ki airlines hi aayenge
json_request=json.dumps(obj)
for y in range(10):
## try:
resp=requests.post(url, data=json_request, headers=headers)
## break
## except:
## continue
j=json.loads(resp.content)
print "airports involved"
for airport in j["trips"]["data"]["airport"]:
print "##"
print airport["code"]
print airport["name"]
##print airport["city"]
print
##print "ye city k baare me"
##for city in j["trips"]["data"]["city"]:
## print "##"
## print city["kind"]
## print city["code"]
## print city["country"]
## print city["name"]
######
####print "ye sab aircrafts available hai"
####print
####for aircraft in j["trips"]["data"]["aircraft"]:
#### print "##"
#### print aircraft["name"]
####
####print
####print "ye carriers k naam"
####print
####for carr in j["trips"]["data"]["carrier"]:
#### print "##"
#### print carr["name"]
#### print "code:"+ carr["code"]
for alltrips in j["trips"]["tripOption"]:
for each in alltrips["slice"]:
print "Duration of the trip"+ str(each["duration"])
## print "the segments that constitute the flight are"
## for seg in each["segment"]:
## print "##"
## print "Duration is "+ str(seg["duration"])
## print "The flight this is a segment of:"
## print "Carrier "+ str(seg["flight"]["carrier"])
## print "In Cabin: " +str(seg["cabin"])
## for leg in seg["leg"]:
## print "Aircraft:"+ str(leg["aircraft"])
## print "Arrival Time "+ str(leg["arrivalTime"])
## print "Departure Time " +str(leg["departureTime"])
## if leg.get("originTerminal"):
##
## print "origin Terminal"+ str(leg["originTerminal"])
## if leg.get("destinationTerminal"):
## print "destination Terminal "+str(leg["destinationTerminal"])
#print "the duration of this leg is" + str(leg["duration"])
for each in alltrips["pricing"]:
## print "the total base fare per passenger " + str(each["baseFareTotal"])
print "total fare so calculated is"
basefare=[int( each["baseFareTotal"].split("R")[1])]
#print basefare
#assert False
print "INR"+str((int(ad)+int(sd)+int(cd)+int(infs))*basefare[0])
#assert False
## print "the horizontal fare Calculation \n"+str(each["fareCalculation"])
## print "**this is devoid of taxes**"