Делаем бота для учета личных расходов на Python используя Google Spreadsheets (часть 2)
Здравствуйте! Продолжим разработку Telegram бота для учета личных расходов на языке Python. В первой части статьи я описал что в качестве базы мы будем использовать Google Spreadsheets и показал как получить токен для работы с таблицей на Python. Сегодня мы создадим Telegram-бот и будем передавать полученные данные в Google-таблицы.
Создание Telegram -бота
Начнем с создания простого бота для Telegram. Для создания бота в телеграме есть специальный мета-бот BotFather (@BotFather). Находим его через поиск в нашем клиенте телеграмма. Список его команд можно получить, написав в чате с ним команду /help.
Для создания нового бота нужно написать команду /newbot и в следующем сообщении передать название бота (должно заканчиваться словом bot). В ответ вам придет сообщение с API токеном — он понадобится нам для создания соединения с телеграммом.
Пишем скрипт обработки на Python
На сегодняшний день существует множество библиотек и инструментов как для работы с ботами Telegram так и для работы с Telegram API. В Python тоже есть множество готовых библиотек и решений для этих задач.
Для нашего проекта будем использовать pyTelegramBotAPI, которая берет на себя все нюансы отправки и получения запросов, позволяя сконцентрироваться непосредственно на логике. Установка библиотеки очень проста:
pip install pytelegrambotapi
Начнем с подключения бота, создаем в отдельной папке файл rasxodibot.py и пишем скрипт для получения входящих сообщений и записи в Google таблицы:
Запускаем наш скрипт:
python rasxodibot.py
Все готово!
Попробуем протестировать наш бот.
Отлично! Данные отправлены на таблицу, проверим нашу таблицу:
Таким образом подключив пару библиотек и написав десятки строк кода можно создавать действительно полезные приложения которые могут облегчить муторные или повторяющиеся дела.
Ниже я разместил пару ссылок, рекомендую вам почитать более подробно про библиотеки работающие с Google-таблицами и Telegram ботами:
gspread – gspread 3.6.0 documentation
Edit description
gspread.readthedocs.io
eternnoir/pyTelegramBotAPI
pyTelegramBotAPI A simple, but extensible Python implementation for the Telegram Bot API. This API is tested with…
github.com
Надеюсь эта серия стало полезным для вас и вы уже сможете создавать для себя маленьких ботов для решения больших проблем!
Ten articles before and after
Controlling Light using Telegram Bot – Telegram Group
Telegram’da Benim de Bir Tuzum Olsun – Telegram Group
How to send photos to Telegram in Ruby – Telegram Group
data-rh=”true”>Explainer: UK News Quiz, a Telegram Bot – Dror Kessler – Medium – Telegram Group
Telegram bot on the cloud. I wanted to create a bot in Telegram… – Telegram Group
data-rh=”true”>Telegram Bot и отчётность по проекту – ToBe – Medium – Telegram Group
Делаем бота для учета личных расходов на Python используя Google Spreadsheets – Telegram Group
[BEST] Tricks To Rank #1 Your Telegram Channel (2022) – Telegram Group
data-rh=”true”>Telegram channel – KYC COIN – Medium – Telegram Group
Telegram Marketing: How to Promote a Startup Channel – Telegram Group