mirror of
https://github.com/KUlishevgeniy/c22712.git
synced 2026-09-24 08:00:22 +00:00
Парсер БОТ
This commit is contained in:
Generated
+6
-8
@@ -5,10 +5,8 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="e5615680-c090-497d-a104-1337ed85f850" name="Changes" comment="Дз парсинг ВВ">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/22712.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/22712.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Задания/task1/Kulikov/L_BOT_try1.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Задания/task1/Prokhorova/парсинггг.py" beforeDir="false" afterPath="$PROJECT_DIR$/Задания/task1/Prokhorova/parsing.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -38,12 +36,12 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"last_opened_file_path": "C:/Users/Honor/Desktop/учеба/прога/c22712/Задания/task1/Prokhorova",
|
||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"last_opened_file_path": "C:/Users/Honor/Desktop/учеба/прога/c22712/Задания/task1/Prokhorova",
|
||||
"settings.editor.selected.configurable": "com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="CopyFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\Honor\Desktop\учеба\прога\c22712\Задания\task1\Prokhorova" />
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import telebot
|
||||
import psycopg2
|
||||
import config
|
||||
bot = telebot.TeleBot(6053050329:AAFEBguQ5-UE80bB_aNjjSoUdIT91BlPJCY)
|
||||
|
||||
def select(request):
|
||||
try:
|
||||
connection = psycopg2.connect(host=config.host, dbname=config.dbname, user=config.user,
|
||||
password=config.password)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(request)
|
||||
result = cursor.fetchall()
|
||||
except:
|
||||
result = "Ошибка"
|
||||
finally:
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return result
|
||||
|
||||
max_id = int(select("select max(id) from laptops")[0][0])
|
||||
bot = telebot.TeleBot(6053050329:AAFEBguQ5-UE80bB_aNjjSoUdIT91BlPJCY)
|
||||
@bot.message_handler(commands=["start"])
|
||||
def start(m, res=False):
|
||||
bot.send_message(m.chat.id, f'Привет. Введите идентификатор от 1 до {max_id}, чтобы получить данные: ')
|
||||
|
||||
@bot.message_handler(content_types=["text"])
|
||||
def from_bd(message):
|
||||
try:
|
||||
current_id = int(message.text)
|
||||
except BaseException:
|
||||
bot.send_message(message.chat.id, "Вы неправильно ввели ID. Попробуйте снова:")
|
||||
return
|
||||
if current_id > max_id:
|
||||
bot.send_message(message.chat.id, "ID больше, чем количество товаров. Попробуйте снова:")
|
||||
return
|
||||
else:
|
||||
try:
|
||||
data = select(f"select * from laptops where id = {current_id}")[0][1:]
|
||||
if type(data) == str:
|
||||
bot.send_message(message.chat.id, "Ошибка на сервере")
|
||||
return
|
||||
s = data[:-1]
|
||||
names_of_columns = ["Товар", "Цена", "Диагональ", "Разрешение", "Процессор", "Оперативная память",
|
||||
"Графический контроллер", "Объём диска"]
|
||||
everydata = []
|
||||
for data_name, column_name in zip(s, names_of_columns):
|
||||
everydata.append(column_name.capitalize() + ": " + data_name)
|
||||
bot.send_message(message.chat.id, "\n\n".join(everydata))
|
||||
bot.send_photo(message.chat.id, open(data[-1], 'rb'))
|
||||
except:
|
||||
bot.send_message(message.chat.id, "Ошибка на сервере")
|
||||
bot.send_message(message.chat.id, f"Введите следующий ID от 1 до {max_id}:")
|
||||
bot.polling(none_stop=True, interval=0)
|
||||
Reference in New Issue
Block a user