Compare commits
No commits in common. "9335b782c2aa31318bf163e62e9c81b1a31b4ad4" and "29ceb95404c276c7d4c694b2976a8f2cac8b1771" have entirely different histories.
9335b782c2
...
29ceb95404
61
main.py
61
main.py
@ -1,9 +1,9 @@
|
||||
import telebot
|
||||
from telebot import types
|
||||
import configparser
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read('config.ini')
|
||||
config.read()
|
||||
|
||||
TG_TOKEN = config.get('telebot', 'token')
|
||||
API_TOKEN = config.get('hotels_api', 'token')
|
||||
@ -13,66 +13,33 @@ DB_DATABASE = config.get('database', 'database')
|
||||
DB_USER = config.get('database', 'user')
|
||||
DB_PASSWORD = config.get('database', 'password')
|
||||
|
||||
|
||||
bot = telebot.TeleBot(token=TG_TOKEN)
|
||||
last_commands = {}
|
||||
|
||||
|
||||
@bot.message_handler(commands=['start', 'help'])
|
||||
def handle_start(message):
|
||||
pass # TODO add logic for handling the start and help commands
|
||||
pass # TODO добавить логику обработки команд start и help
|
||||
|
||||
|
||||
@bot.message_handler(commands=['lowprice'])
|
||||
def handle_lowprice(message):
|
||||
last_commands[message.chat.id] = 'lowprice'
|
||||
|
||||
# Create InlineKeyboardMarkup with buttons
|
||||
keyboard = types.InlineKeyboardMarkup(row_width=5)
|
||||
buttons = [types.InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1, 11)]
|
||||
keyboard.add(*buttons)
|
||||
|
||||
# Send keyboard with buttons
|
||||
bot.send_message(message.chat.id, 'Выберите количество:', reply_markup=keyboard)
|
||||
@bot.message_handler(commands=['low'])
|
||||
def handle_low(message):
|
||||
pass # TODO добавить логику обработки команды low
|
||||
|
||||
|
||||
@bot.message_handler(commands=['highprice'])
|
||||
def handle_highprice(message):
|
||||
last_commands[message.chat.id] = 'highprice'
|
||||
|
||||
# Create InlineKeyboardMarkup with buttons
|
||||
keyboard = types.InlineKeyboardMarkup(row_width=5)
|
||||
buttons = [types.InlineKeyboardButton(str(i), callback_data=str(i)) for i in range(1, 11)]
|
||||
keyboard.add(*buttons)
|
||||
|
||||
# Send keyboard with buttons
|
||||
bot.send_message(message.chat.id, 'Выберите количество:', reply_markup=keyboard)
|
||||
@bot.message_handler(commands=['high'])
|
||||
def handle_high(message):
|
||||
pass # TODO добавить логику обработки команды high
|
||||
|
||||
|
||||
@bot.message_handler(commands=['bestdeal'])
|
||||
def handle_bestdeal(message):
|
||||
pass # TODO add logic for handling the bestdeal command
|
||||
@bot.message_handler(commands=['custom'])
|
||||
def handle_custom(message):
|
||||
pass # TODO добавить логику обработки команды custom
|
||||
|
||||
|
||||
@bot.message_handler(commands=['history'])
|
||||
def handle_history(message):
|
||||
pass # TODO add logic for handling the history command
|
||||
|
||||
|
||||
@bot.callback_query_handler(func=lambda call: True) # Handler for button clicks
|
||||
def handle_button_click(call):
|
||||
if call.message.chat.id in last_commands:
|
||||
command = last_commands[call.message.chat.id] # Get the current command from the last commands dict
|
||||
|
||||
bot.edit_message_reply_markup(call.message.chat.id, call.message.message_id) # Remove the keyboard
|
||||
|
||||
# Edit the message.
|
||||
bot.edit_message_text(
|
||||
text=f'Вы выбрали количество: {call.data} ({last_commands[call.message.chat.id]})',
|
||||
chat_id=call.message.chat.id,
|
||||
message_id=call.message.message_id
|
||||
)
|
||||
|
||||
del last_commands[call.message.chat.id] # Remove the last command state after handling
|
||||
pass # TODO добавить логику обработки команды history
|
||||
|
||||
|
||||
bot.polling()
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
import json
|
||||
|
||||
|
||||
class RegionNames(BaseModel):
|
||||
fullName: str
|
||||
shortName: str
|
||||
displayName: str
|
||||
primaryDisplayName: str
|
||||
secondaryDisplayName: str
|
||||
lastSearchName: str
|
||||
|
||||
|
||||
class EssId(BaseModel):
|
||||
sourceName: str
|
||||
sourceId: int
|
||||
|
||||
|
||||
class Country(BaseModel):
|
||||
name: str
|
||||
isoCode2: str
|
||||
isoCode3: str
|
||||
|
||||
|
||||
class HierarchyInfo(BaseModel):
|
||||
country: Country
|
||||
|
||||
|
||||
class Coordinates(BaseModel):
|
||||
lat: float
|
||||
long: float
|
||||
|
||||
|
||||
class GaiaRegionResult(BaseModel):
|
||||
index: int
|
||||
gaiaId: int
|
||||
type: str
|
||||
regionNames: RegionNames
|
||||
essId: EssId
|
||||
coordinates: Coordinates
|
||||
hierarchyInfo: HierarchyInfo
|
||||
|
||||
|
||||
class SearchResults(BaseModel):
|
||||
q: str
|
||||
rid: str
|
||||
rc: str
|
||||
sr: list[GaiaRegionResult]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open('locations_v3_search_example.json', 'r', encoding='utf-8') as json_file:
|
||||
data = json.load(json_file)
|
||||
results = SearchResults(**data)
|
||||
print('\n'.join(
|
||||
[result.regionNames.fullName for result in results.sr if result.type in ('CITY', 'NEIGHBORHOOD')])
|
||||
)
|
||||
@ -1,298 +0,0 @@
|
||||
{
|
||||
"q":"Нью Йорк",
|
||||
"rid":"fbab370c153d458ea91ce8557d32fa71",
|
||||
"rc":"OK",
|
||||
"sr":[
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"0",
|
||||
"gaiaId":"2621",
|
||||
"type":"CITY",
|
||||
"regionNames":{
|
||||
"fullName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Нью-Йорк",
|
||||
"displayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Нью-Йорк",
|
||||
"secondaryDisplayName":"Нью-Йорк, США",
|
||||
"lastSearchName":"Нью-Йорк"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"2621"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.712843",
|
||||
"long":"-74.005966"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"1",
|
||||
"gaiaId":"553248633938969338",
|
||||
"type":"NEIGHBORHOOD",
|
||||
"regionNames":{
|
||||
"fullName":"Центральный Нью-Йорк, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Центральный Нью-Йорк",
|
||||
"displayName":"Центральный Нью-Йорк, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Центральный Нью-Йорк",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Центральный Нью-Йорк"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"553248633938969338"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.759591",
|
||||
"long":"-73.984912"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"2",
|
||||
"gaiaId":"129440",
|
||||
"type":"NEIGHBORHOOD",
|
||||
"regionNames":{
|
||||
"fullName":"Манхэттен, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Манхэттен",
|
||||
"displayName":"Манхэттен, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Манхэттен",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Манхэттен"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"129440"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.783062",
|
||||
"long":"-73.971252"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"3",
|
||||
"gaiaId":"177851",
|
||||
"type":"CITY",
|
||||
"regionNames":{
|
||||
"fullName":"Бруклин, Нью-Йорк, США",
|
||||
"shortName":"Бруклин",
|
||||
"displayName":"Бруклин, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Бруклин",
|
||||
"secondaryDisplayName":"Нью-Йорк, США",
|
||||
"lastSearchName":"Бруклин"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"177851"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.678177",
|
||||
"long":"-73.94416"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"4",
|
||||
"gaiaId":"4933194",
|
||||
"type":"AIRPORT",
|
||||
"regionNames":{
|
||||
"fullName":"Нью-Йорк, Нью-Йорк, США (JFK-Джон Ф. Кеннеди, международный)",
|
||||
"shortName":"Нью-Йорк, Нью-Йорк (JFK-Джон Ф. Кеннеди, международный)",
|
||||
"displayName":"Нью-Йорк (JFK - Джон Ф. Кеннеди, международный), Нью-Йорк, США",
|
||||
"primaryDisplayName":"Нью-Йорк (JFK - Джон Ф. Кеннеди, международный)",
|
||||
"secondaryDisplayName":"Нью-Йорк, США",
|
||||
"lastSearchName":"Нью-Йорк (JFK - Джон Ф. Кеннеди, международный)"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"4933194"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.644166",
|
||||
"long":"-73.782548"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
},
|
||||
"isMinorAirport":"false"
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"5",
|
||||
"gaiaId":"6141743",
|
||||
"type":"POI",
|
||||
"regionNames":{
|
||||
"fullName":"Всемирный финансовый центр, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Всемирный финансовый центр",
|
||||
"displayName":"Всемирный финансовый центр, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Всемирный финансовый центр",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Всемирный финансовый центр"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"6141743"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.71285",
|
||||
"long":"-74.014432"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"6",
|
||||
"gaiaId":"6056463",
|
||||
"type":"POI",
|
||||
"regionNames":{
|
||||
"fullName":"Центральный парк, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Центральный парк",
|
||||
"displayName":"Центральный парк, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Центральный парк",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Центральный парк"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"6056463"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.78072",
|
||||
"long":"-73.966802"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"7",
|
||||
"gaiaId":"6004547",
|
||||
"type":"NEIGHBORHOOD",
|
||||
"regionNames":{
|
||||
"fullName":"Бруклин-Хайтс, Нью-Йорк, США",
|
||||
"shortName":"Бруклин-Хайтс",
|
||||
"displayName":"Бруклин-Хайтс, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Бруклин-Хайтс",
|
||||
"secondaryDisplayName":"Нью-Йорк, США",
|
||||
"lastSearchName":"Бруклин-Хайтс"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"6004547"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.696762414204954",
|
||||
"long":"-73.99526676287296"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"8",
|
||||
"gaiaId":"800075",
|
||||
"type":"NEIGHBORHOOD",
|
||||
"regionNames":{
|
||||
"fullName":"Верхний район Уэст-Сайд, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Верхний район Уэст-Сайд",
|
||||
"displayName":"Верхний район Уэст-Сайд, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Верхний район Уэст-Сайд",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Верхний район Уэст-Сайд"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"800075"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.78701",
|
||||
"long":"-73.975365"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"@type":"gaiaRegionResult",
|
||||
"index":"9",
|
||||
"gaiaId":"800076",
|
||||
"type":"NEIGHBORHOOD",
|
||||
"regionNames":{
|
||||
"fullName":"Верхний район Ист-Сайд, Нью-Йорк, Нью-Йорк, США",
|
||||
"shortName":"Верхний район Ист-Сайд",
|
||||
"displayName":"Верхний район Ист-Сайд, Нью-Йорк, Нью-Йорк, США",
|
||||
"primaryDisplayName":"Верхний район Ист-Сайд",
|
||||
"secondaryDisplayName":"Нью-Йорк, Нью-Йорк, США",
|
||||
"lastSearchName":"Верхний район Ист-Сайд"
|
||||
},
|
||||
"essId":{
|
||||
"sourceName":"GAI",
|
||||
"sourceId":"800076"
|
||||
},
|
||||
"coordinates":{
|
||||
"lat":"40.773563",
|
||||
"long":"-73.956558"
|
||||
},
|
||||
"hierarchyInfo":{
|
||||
"country":{
|
||||
"name":"Соединенные Штаты",
|
||||
"isoCode2":"US",
|
||||
"isoCode3":"USA"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user