-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtequila_api.py
47 lines (41 loc) · 1.52 KB
/
tequila_api.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
import requests
from constants import TequilaConst
class TequilaApi(TequilaConst):
"""Manages connection with tequila api"""
def __init__(self):
self.response_json = {}
def request_data(self, city):
"""Requests data from tequila API"""
parameters = {
"term": city,
}
response_tequila = requests.get(url=self.TEQUILA_QUERY_ENDPOINT, params=parameters,
headers=self.TEQUILA_HEADERS)
response_tequila.raise_for_status()
self.response_json = response_tequila.json()
def search_flights(self, fly_from: str, fly_to: str, date_from: str, date_to: str):
"""Requests data from tequila api"""
parameters = {
"fly_from": fly_from,
"fly_to": fly_to,
"date_from": date_from,
"date_to": date_to,
"nights_in_dst_from": 7,
"nights_in_dst_to": 21,
"one_for_city": 1,
"max_stopovers": 0,
}
response = requests.get(
url=self.TEQUILA_SEARCH_ENDPOINT,
params=parameters,
headers=self.TEQUILA_HEADERS
)
response.raise_for_status()
if not response.json()["data"]:
parameters["max_stopovers"] = 2
response = requests.get(
url=self.TEQUILA_SEARCH_ENDPOINT,
params=parameters,
headers=self.TEQUILA_HEADERS)
response.raise_for_status()
self.response_json = response.json()