Good afternoon, tell me please, there is a website (there is no access to the code, etc.). They post tables on it. For example, the work plan for the month. So, how to make these tables, 2 hours before the start of work, they sent the message to the right people in telegrams. There was an idea to pull out the table, add auto-posting to the group in VC at the right time and immediately repost to the telegrams. How to automate all this? Where to dig, what to read? Or maybe there are other options? Plus, these tables can be updated, so you need the script to update the data in the table every 30 minutes, for example.

  • one
    With such a vague question, you can only recommend learning programming languages, methods of parsing HTML documents and the Telegram Bot API. - neluzhin
  • The question is most likely in the algorithm. What should it be and what is needed for this? What technologies to use? automatic parsing + autoposting in vk + repost in telegrams via ifttt? or maybe somehow easier to do? - Oleh

1 answer 1

Actually, the task consists of three parts:

  1. How to pull tables;
  2. How to send information to telegrams;
  3. How to perform the task periodically.

Since it is not indicated in which language and in which system it is necessary to solve the problem, we will choose the language and system arbitrarily: let it be Linux and Python.

How to pull tables

Read about Python HAML scraping. I recommend lxml or BeautifulSoup: Example:

import urllib2 # ΠΎΡ‚ΠΊΡƒΠ΄Π° скачиваСм тСкст wiki = "https://en.wikipedia.org/wiki/" #Π‘ΠΊΠ°Ρ‡ΠΈΠ²Π°Π΅ΠΌ тСкст, Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Π² page page = urllib2.urlopen(wiki) #ΠΈΠΌΠΏΠΎΡ€Ρ‚ΠΈΡ€ΡƒΠ΅ΠΌ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ для парсинга ΠΈΠ· bs4 from bs4 import BeautifulSoup #выполняСм парсинг soup = BeautifulSoup(page) # дальшС ΠΌΠΎΠΆΠ½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ с Π΄Π°Π½Π½Ρ‹ΠΌΠΈ находящимися Π² soup 

How to send information to a telegram

There is a huge number of implementations of the Bot API telegram that interests us in this case (in general, as Anatol rightly points out , there are two APIs: the Telegram API and the Bot API; in this case, we are interested in the second).

We use, for example, telepot:

 import telepot bot = telepot.Bot('*** INSERT TOKEN ***') chait_id = ... bot.sendMessage(chat_id, "insert your message") 

How to perform a task periodically

Here there are several options, which can be divided into two groups:

  1. Use an external service for this (for example, cron);
  2. Use any internal module for periodic execution of the task.

In the second case, I recommend the schedule package. Simple and beautiful:

 import schedule import time def job(): print("I'm working...") schedule.every(10).minutes.do(job) schedule.every().hour.do(job) schedule.every().day.at("10:30").do(job) schedule.every().monday.do(job) schedule.every().wednesday.at("13:15").do(job) while True: schedule.run_pending() time.sleep(1) 
  • There is a huge number of implementations of clients API telegram. - are you talking about the bot API or about the Telegram API ? - Anatol
  • @Anatol: About the Bot API; clarified in the text; Thanks for the fair comment! - Igor Chubin
  • You can solve with the help of both api, if they described both options - it would be super - Anatol
  • one
    @Anatol: Let's do it - Igor Chubin