-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbus.py
51 lines (48 loc) · 1.62 KB
/
bus.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
from pprint import pprint
import requests
import json
app_id="Insert id here"
api_key="Insert key here"
base_url="http://developer.goibibo.com/api/bus/search/?app_id=app_id&app_key=api_key&format=json&"
def search(src,dest,dateDep):
dateDep=str(dateDep)
url=base_url+"source="+src+"&destination="+dest+"&dateofdeparture="+dateDep
response = requests.get(url)
data = response.json()
data = data["data"]["onwardflights"]
res=""
for row in data:
res+="Origin:"+row["origin"]+"\n"
res+="Destination:"+row["destination"]+"\n"
res+="Departure Time:"+row["DepartureTime"]+"\n"
res+="Arrival Time:"+row["ArrivalTime"]+"\n"
res+="Seat:"+row["seat"]+"\n"
res+="Duration:"+row["duration"]+"\n"
res+="Type:"+row["BusType"]+"\n"
res+="Fare:"+row["fare"]["totalfare"]+"\n"
res+="Travels Name"+row["TravelsName"]+"\n"
res+="\n"
return res
def filter1(src,dest,dateDep,filter):
dateDep=str(dateDep)
url=base_url+"source="+src+"&destination="+dest+"&dateofdeparture="+dateDep
response = requests.get(url)
data = response.json()
data = data["data"]["onwardflights"]
res=""
for row in data:
if(filter in row["seat"]):
res+="Origin:"+row["origin"]+"\n"
res+="Destination:"+row["destination"]+"\n"
res+="Departure Time:"+row["DepartureTime"]+"\n"
res+="Arrival Time:"+row["ArrivalTime"]+"\n"
res+="Seat:"+row["seat"]+"\n"
res+="Duration:"+row["duration"]+"\n"
res+="Type:"+row["BusType"]+"\n"
res+="Fare:"+row["fare"]["totalfare"]+"\n"
res+="Travels Name:"+row["TravelsName"]+"\n"
res+="\n"
return res
seat_type_filter = "ST"
result = filter1("bangalore","mangalore","20180301",seat_type_filter)
print(result)