-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
91 lines (81 loc) · 4.29 KB
/
config.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
import os
import requests
import re
class Hotels:
"""Класс, описывающий структуру данных об отеле"""
def __init__(self, name, address, dist, price):
self.name = name
self.address = address
self.dist = dist
self.price = price
class Req:
"""Класс, описывающий структуру API-запросов"""
citi_id = None
cmd = None
citi_name = None
hmh = None
result = []
range_price = None
range_dis = None
citi_res = None
def get_citi_ID(self):
"""Метод выполняет запрос по переменной citi_nama. Возвращает id-города и геоданные."""
url = "https://hotels4.p.rapidapi.com/locations/v2/search"
querystring = {"query": self.citi_name,
"locale": "ru_RU", "currency": "USD"}
headers = {
'x-rapidapi-key': os.getenv('x-rapidapi-key'),
'x-rapidapi-host': os.getenv('x-rapidapi-host')
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
return response.json()['suggestions'][0]['entities'][0]['destinationId'], \
(response.json()['suggestions'][0]
['entities'][0]['caption']).split(',')
def top_hotels_LP(self):
"""Метод выполные запраос с citi_id, возвращает json данные обо всех отелях города.
Отсортировано по цене по возрастанию"""
url = "https://hotels4.p.rapidapi.com/properties/list"
querystring = {"destinationId": self.citi_id, "pageNumber": "1", "pageSize": "25", "checkIn": "2020-01-08",
"checkOut": "2020-01-15", "adults1": "1", "sortOrder": "PRICE", "locale": "ru_RU",
"currency": "RUB"}
headers = {
'x-rapidapi-key': os.getenv('x-rapidapi-key'),
'x-rapidapi-host': os.getenv('x-rapidapi-host')
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
Req.result = response.json(
)['data']['body']['searchResults']['results']
def top_hotels_HP(self):
"""Метод выполные запраос с citi_id, возвращает json данные обо всех отелях города.
Отсортировано по цене по убыванию"""
url = "https://hotels4.p.rapidapi.com/properties/list"
querystring = {"destinationId": self.citi_id, "pageNumber": "1", "pageSize": "25", "checkIn": "2020-01-08",
"checkOut": "2020-01-15", "adults1": "1", "sortOrder": "PRICE_HIGHEST_FIRST", "locale": "ru_RU",
"currency": "RUB"}
headers = {
'x-rapidapi-key': os.getenv('x-rapidapi-key'),
'x-rapidapi-host': os.getenv('x-rapidapi-host')
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
Req.result = response.json(
)['data']['body']['searchResults']['results']
def top_hotels_BD(self):
"""Метод выполняет запрос с citi_id и диапазонами цен и расстояния,
возвращает json данные обо всех отелях города. Отсортировано по цене по убыванию"""
url = "https://hotels4.p.rapidapi.com/properties/list"
querystring = {"destinationId": self.citi_id, "pageNumber": "1", "pageSize": "25", "checkIn": "2020-01-08",
"checkOut": "2020-01-15", "adults1": "1", "priceMin": Req.range_price.split('-')[0],
"priceMax": Req.range_price.split('-')[1],
"sortOrder": "PRICE", "locale": "ru_RU",
"currency": "RUB"}
headers = {
'x-rapidapi-key': os.getenv('x-rapidapi-key'),
'x-rapidapi-host': os.getenv('x-rapidapi-host')
}
response = requests.request(
"GET", url, headers=headers, params=querystring)
Req.result = response.json(
)['data']['body']['searchResults']['results']