import telebot
import requests
from bs4 import BeautifulSoup as bs
bot = telebot.TeleBot('Token')
new = ''
n = []
num = 0
new = dict()
d = {}
t = 0
y = 0
def zapoln(message):
global new
global y
global d
if y == 1:
d[message.chat.id] = n
new = {key: [] for key in n}
rass(message)
def rass(message):
while True:
with open('input.txt','w') as inp:
for key,val in d.items():
inp.write('{}:{}\n'.format(key,val))
import random
global new
global n
global num
p = random.choice(n)
url = f'https://t.me/s/{p}'
response = requests.get(url)
soup = bs(response.text, 'lxml')
teg = soup.find_all('div', class_='tgme_widget_message_wrap')
div = soup.find_all('div', class_='tgme_widget_message')
next = soup.find_all('div', class_='tgme_widget_message_bubble')
text_ = soup.find_all('div', class_='tgme_widget_message_text')
s = []
out = ''
for i in text_:
s.append(i)
try:
out = str(s[-1])
except IndexError:
bot.send_message(message.chat.id, 'Вы неправильно ввели какал!')
num = 0
n = []
kanal(message)
out = out[65:]
out = out[:-6]
for _ in range(out.count('<')):
a = out.find('<')
b = out.find('>')
s = out[a:b+1]
out = out.replace(s, '')
if out == new[p]:
pass
else:
new[p] = out
bot.send_message(message.chat.id, f'{out}\n-----\nНовость от @{p}')
print(out)
def proverka(message):
global n
global t
global num
if message.text.lower() == 'стоп' and n != []:
num = 1
print(n)
zapoln(message)
else:
if t != 1:
n.append(message.text)
bot.send_message(message.chat.id, 'Напиши комманду: "/next"')
def kanal(message):
if t != 1:
msg = bot.send_message(message.chat.id, 'Введите название канала БЕЗ @ например: rian_ru. Если больше не хотите вводить названия напишите "Стоп"')
bot.register_next_step_handler(msg, proverka)
else:
rass(message)
@bot.message_handler(commands='next')
def pr(message):
if num == 0:
kanal(message)
else:
rass(message)
@bot.message_handler(commands='start')
def nav(message):
global t
global y
global n
with open('input.txt') as inp:
for i in inp.readlines():
key,val = i.strip().split(':')
d[key] = val
if message.chat.id in d:
n = d[message.chat.id]
t = 1
else:
y = 1
d[message.chat.id] = n
pr(message)
bot.polling()
Traceback (most recent call last):
File "c:\Users\Student\Documents\GitHub\arhipT999.github.io\tbot.py", line 111, in <module>
bot.polling()
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 664, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 726, in __threaded_polling
raise e
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 686, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 136, in raise_exceptions
raise self.exception_info
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 88, in run
task(*args, **kwargs)
File "c:\Users\Student\Documents\GitHub\arhipT999.github.io\tbot.py", line 108, in nav
pr(message)
File "c:\Users\Student\Documents\GitHub\arhipT999.github.io\tbot.py", line 89, in pr
kanal(message)
File "c:\Users\Student\Documents\GitHub\arhipT999.github.io\tbot.py", line 84, in kanal
rass(message)
File "c:\Users\Student\Documents\GitHub\arhipT999.github.io\tbot.py", line 33, in rass
p = random.choice(n)
File "C:\Users\Student\AppData\Local\Programs\Python\Python310\lib\random.py", line 378, in choice
return seq[self._randbelow(len(seq))]
IndexError: list index out of range
-1001682669467:['breakingmash']
5131695189:['breakingmash', 'rian_ru']