-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeguiTuBus.py
129 lines (109 loc) · 4.87 KB
/
SeguiTuBus.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
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
import requests
BASE_URL = "https://seguitubus.trescruces.com.uy/api/auth/app"
VERSION = '7.0'
class STB:
def __init__(self) -> None:
'''Initialize the class'''
self.headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
pass
def _make_request(self, path:str, headers=None, json={}):
'''
Handle server requests
Parameters:
path (str): path of request
headers (dict): headers(optional)
json (dict): data(optional)
Returns:
binary_sum (str): Binary string of the sum of a and b
'''
if headers == None:
headers = self.headers
return requests.post(f'{BASE_URL}/{path}', headers=headers, json=json)
def _list_config(self):
'''
Retrive Config List
Returns:
config (dict): config list
'''
return (self._make_request('WSlistconfig').json())
def _version(self):
'''
Retrive version data
Returns:
version (dict): version list
'''
headers = self.headers.copy()
headers['X-Requested-With'] = 'XMLHttpRequest'
return (self._make_request('WSversion', headers=headers, json={'version': VERSION}
).json())
def list_serv(self, Empresa: str = None, HoraInicio: str = None, Origen: str = None,
Destino: str = None, NroServicio: str = None, VarianteServicio: str = None) -> dict:
'''
Retrives and filters buses
Parameters:
Empresa (str): Buses Company
HoraInicio (str): Buses Departure Time
Origen (str): Buses Origin
Destino (str): Buses Destination
NroServicio (str): Bus Service Number
VarianteServicio (str): Bus variant (self.list_arrays()['response']['tipos'] to get variants list)
Returns:
service list (dict): list of services
'''
t = {}
if Empresa != None:
t['Empresa'] = Empresa.upper()
if HoraInicio != None:
t['HoraInicioTeorica'] = HoraInicio.upper()
if Origen != None:
t['Origen'] = Origen.upper()
if Destino != None:
t['Destino'] = Destino.upper()
if NroServicio != None:
t['nroServicio'] = NroServicio.upper()
if VarianteServicio != None:
t['VarianteServicio'] = VarianteServicio.upper()
return (self._make_request('WSlistserv', json={'filtros': t}).json())
def info_bus(self, Bus: str):
return (self._make_request('WSinfobus', json={'bus': Bus}).json())
def list_serv_map(self, Empresa: str = None, HoraInicio: str = None, Origen: str = None,
Destino: str = None, NroServicio: str = None, VarianteServicio: str = None) -> dict:
'''
Retrives and filters buses
Parameters:
Empresa (str): Buses Company (self.list_arrays()['response']['empresas'] to get company list)
HoraInicio (str): Buses Departure Time
Origen (str): Buses Origin (self.list_arrays()['response']['ciudades'] to get cities list)
Destino (str): Buses Destination (self.list_arrays()['response']['ciudades'] to get cities list)
NroServicio (str): Bus Service Number
VarianteServicio (str): Bus variant (self.list_arrays()['response']['tipos'] to get variants list)
Returns:
service list (dict): list of services
'''
t = {}
if Empresa != None:
t['Empresa'] = Empresa.upper()
if HoraInicio != None:
t['HoraInicioTeorica'] = HoraInicio.upper()
if Origen != None:
t['Origen'] = Origen.upper()
if Destino != None:
t['Destino'] = Destino.upper()
if NroServicio != None:
t['nroServicio'] = NroServicio.upper()
if VarianteServicio != None:
t['VarianteServicio'] = VarianteServicio.upper()
headers = self.headers.copy()
headers['X-Requested-With'] = 'XMLHttpRequest'
return (self._make_request('WSlistservmap', json={'filtros': t}).json())
def location(self, Bus):
headers = self.headers.copy()
headers['X-Requested-With'] = 'XMLHttpRequest'
return (self._make_request('WSlocation', json={'bus': Bus}).json())
def list_arrays(self):
headers = self.headers.copy()
headers['X-Requested-With'] = 'XMLHttpRequest'
return (self._make_request('WSlistarrays', json={}).json())