ПКС / ПКС. Материалы лекций
.pdf6. Пример кода для управления данными мессенджере Telegram |
161 |
с помощью БД MySQL (файл tg_bot.py) |
def func_unknown(self, update, context): context.bot.send_message(chat_id=update.effective_chat.id, text="Введена
неизвестная команда")
def func_insert(self, update, context): if len(context.args) == 3:
text_reply = self.dbase.insert_data([context.args[0], context.args[1], context.args[2]])
context.bot.send_message(chat_id=update.effective_chat.id, text=text_reply)
return 1
else: context.bot.send_message(chat_id=update.effective_chat.id,
text='для команды /insert необходимо указать аргумент;' 'указано число аргументов: {}'.format(len(context.args)))
return -1
def func_select(self, update, context): if len(context.args) == 1:
text_reply = self.dbase.select_data(context.args[0]) context.bot.send_message(chat_id=update.effective_chat.id,
text=text_reply) return 1
else: context.bot.send_message(chat_id=update.effective_chat.id,
text='для команды /select необходимо указать 1 аргумент или без аргументов;'
'указано число аргументов: {}'.format(len(context.args))) return -1
def func_delete(self, update, context): if len(context.args) == 1:
text_reply = self.dbase.delete_data(context.args[0]) context.bot.send_message(chat_id=update.effective_chat.id,
text=text_reply) return 1
else: context.bot.send_message(chat_id=update.effective_chat.id,
text='для команды /delete необходимо указать 1 аргумент'.format(len(context.args))) return -1
def func_update(self, update, context): if len(context.args) == 2:
text_reply = self.dbase.update_data(context.args[0], context.args[1]) context.bot.send_message(chat_id=update.effective_chat.id,
text=text_reply) return 1
else: context.bot.send_message(chat_id=update.effective_chat.id,
text='для команды /delete необходимо указать 2 аргумента'.format(len(context.args))) return -1
if __name__ == '__main__': new_bot = tg_bot()
Список литературы |
162 |
|
1.Simple Whatsapp Automation Using Python3 and Selenium : [Electronic Resource]. – 2019. – URL: https://medium.com/analytics-vidhya/simple-whatsapp-automation-using-python3-and-selenium-77dad606284b
2.Плас, Дж. Вандер. Python для сложных задач: наука о данных и машинное обучение : [Электронный ресурс] / Дж.
Вандер Плас. – Санкт-Петербург : Питер, 2018. – 576 с. : ил. – URL: http://ibooks.ru/reading.php?productid=356721
3.Северенс, Ч. Введение в программирование на Python : [Электронный ресурс]: учебное пособие / Ч. Северенс. – 2-е
изд. – Москва : ИНТУИТ, 2016. 231 с. – URL: https://e.lanbook.com/book/100703
4.Practical Microservices Development Patterns: CRUD Vs. CQRS : [Electronic Resource]. – 2020. – URL: https://hackernoon.com/practical-microservices-development-patterns-crud-vs-cqrs-h6m3y5y
5.PyCharm. The Python IDE for Professional Developers : [Electronic Resource]. – URL: https://www.jetbrains.com/pycharm/
6.Driver requirements: Documentation for Selenium [Electronic Resource]. – URL: https://www.selenium.dev/documentation/en/webdriver/driver_requirements/
7.Spyne: PRC that doesn't break your back [Electronic Resource]. – 2021. – URL: http://spyne.io/
8.SOAP и REST сервисы с помощью Python-библиотеки Spyne [Electronic Resource]. – 2017. – URL: https://habr.com/ru/post/334290/