The story of how the parser has turned into a full-fledged MRCA bot for Telegram

Welcome, Harrowdene! I recently wrote article about how to write parsers diary, MRCO, and in the end I promised to write about the integration with Telegram. bot, sorry about what. Now bot is ready and fully operational. I want to tell you that he used and the difficulties encountered in this work.


Telegram and Python


To create a my bot (@mrkorobot), I decided to use the library pyTelegramBotAPI. It is easy to install, convenient to use and it even has a nice a book. In the bot I use the following libraries:


the

to access the diary you need a username and password. The first thing you need to prompt the user and put into the database. Once the username and password is required every time the user accesses the bot, we had to choose quick database. My choice fell on Redis, and to run it in Python it was decided to use the library. Pre-encrypting the password in md5 using the built-in Python library hashlib, I put them in the database under the key name is simply the user id in the Telegram. Here's a visual representation:


the
{
"userid": ["login", "пароль_в_MD5"]
}

When using this scheme, we can immediately check if the cell with that id is, then the user is authorized, otherwise, not.


the result is a bot that can show your schedule by day, homework, assessment items and even attachments, if any.


Daily alert


basically, at the moment, the implementation of the safe homework ends, but I wanted to go further and make a daily notification about grades. On reflection, I was able to write a simple script that I added to cron, to generate an expression here. The logic is painfully simple: first extracted a list of all authorized users (provided the bot login and password) and check if the user has enabled notifications daily, if so send grades in this format:


Diary.Bot


Never check the diary was not so easy!


private messages


I wanted to implement the function of viewing personal messages. "Why not?" thought I wrote a method that allows you to view incoming messages. Nothing complicated, surprisingly, wasn't here. Just it is necessary to apply to the mrko.mos.ru/dnevnik/services/dnevnik.php?r=1&first=1, and mrko.mos.ru/dnevnik/services/mail.php?r=0. Then the usual parsing and here all is ready:


Diary.Bot


Diary.Bot


by the Way, the hosting was the problem: from the server to Google Cloud Platform was inaccessible for reasons unknown to me the domain mrko.mos.ru, so I had to place the bot from a friend.


For me it is very important that you try Diary.Bot
(@mrkorobot) in the work and gave their views. All ideas are considered very carefully. Happy coding!

Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

The use of Lisp in production

FreeBSD + PostgreSQL: tuning the database server

As we did a free Noodle for iOS and how we plan to earn