Advertisement
askanton

bot

Apr 12th, 2021
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.39 KB | None | 0 0
  1. import os
  2. import sys
  3. import telebot
  4. import time
  5. import logging
  6. from bs4 import BeautifulSoup
  7. import requests
  8. from data import TOKEN, list
  9.  
  10. logging.basicConfig(filename="logfile.py", level=logging.INFO)
  11. bot = telebot.TeleBot(TOKEN)
  12.  
  13.  
  14. class Kanal:
  15.     name: str = list[0]
  16.     stpage: int = list[1]
  17.     embaded: str = "?embed=1"
  18.  
  19.  
  20. def solver(link):
  21.     try:
  22.         bot.send_message(chat_id=-1001230182875, text=link)
  23.         logging.info('No problem detected')
  24.     except OSError:
  25.         logging.info("ConnectionError - Sending again after 5 seconds!!!")
  26.         time.sleep(5)
  27.         bot.send_message(chat_id=-1001230182875, text=link)
  28.         logging.info('Problem solved')
  29.  
  30. def collector():
  31.     logging.info("Collector started")
  32.     counter = 0
  33.     counter2 = 1
  34.     Kanal.name = list[counter]
  35.     Kanal.stpage = list[counter2]
  36.     while True:
  37.         clear = lambda: os.system('cls')
  38.         clear()
  39.         print()
  40.         print("      />  フ")
  41.         print("     |  0 0 |")
  42.         print("     /`ミ _x 彡")
  43.         print("     /      |")
  44.         print("    /  ヽ   ノ")
  45.         print(" / ̄|   | | |")
  46.         print(" | ( ̄ヽ__ヽ_)_)")
  47.         print(" \二つ")
  48.         print("Проверяем канал ", Kanal.name)
  49.         time.sleep(2)
  50.         clear = lambda: os.system('cls')
  51.         clear()
  52.         print()
  53.         print("      |>  フ ")
  54.         print("     |  0 0  |")
  55.         print("     /ミ x_ 彡")
  56.         print("     /      |")
  57.         print("    /  ヽ   ノ")
  58.         print(" / ̄|   | | |")
  59.         print(" | ( ̄ヽ__ヽ_)_)")
  60.         print(" \二つ")
  61.         print("Проверяем канал ", Kanal.name)
  62.         time.sleep(2)
  63.         r = requests.get(Kanal.name + str(Kanal.stpage) + Kanal.embaded)
  64.         data = r.text
  65.         soup = BeautifulSoup(data, 'lxml')
  66.         pg_not_fnd = soup.find_all("div", {"class": "tgme_widget_message_error"})
  67.         if len(pg_not_fnd) > 0:
  68.             counter = counter + 2
  69.             counter2 = counter2 + 2
  70.             stop = len(list)
  71.             if counter >= stop:
  72.                 logging.info("Sleeping")
  73.                 for i in reversed(range(1, 500)):
  74.                     time.sleep(1)
  75.                     clear = lambda: os.system('cls')
  76.                     clear()
  77.                     print()
  78.                     print("      />  フ")
  79.                     print("     |  _  _|")
  80.                     print("     /`ミ _x 彡")
  81.                     print("     /      |")
  82.                     print("    /  ヽ   ノ")
  83.                     print(" / ̄|   | | |")
  84.                     print(" | ( ̄ヽ__ヽ_)_)")
  85.                     print(" \二つ")
  86.                     print()
  87.                     sys.stderr.write(f"{i:2d}\r")
  88.                     time.sleep(1)
  89.  
  90.                     time.sleep(1)
  91.                     clear = lambda: os.system('cls')
  92.                     clear()
  93.                     print()
  94.                     print("      />  フ")
  95.                     print("     |  _  _|")
  96.                     print("     /`彡 _Х ミ")
  97.                     print("     /      |")
  98.                     print("    /  ヽ   ノ")
  99.                     print(" / ̄|   | | |")
  100.                     print(" | ( ̄ヽ__ヽ_)_)")
  101.                     print(" \二つ")
  102.                     print()
  103.                     sys.stderr.write(f"{i:2d}\r")
  104.                     time.sleep(1)
  105.                 break
  106.             Kanal.name = list[counter]
  107.             Kanal.stpage = list[counter2]
  108.         else:
  109.             for results in soup.find_all("a", {"class": "tgme_widget_message_date"}):
  110.                 link = results.get('href')
  111.                 list[counter2] = int(list[counter2]) + 1
  112.                 solver(link)
  113.                 output = open("data.py", 'w')
  114.                 print("TOKEN = '11*************************************************'", file=output)
  115.                 print("list =", list, file=output)
  116.                 output.close()
  117.             Kanal.stpage = str(int(Kanal.stpage) + 1)
  118.  
  119.  
  120. while True:
  121.     logging.info("Reboot True")
  122.     collector()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement