Add auto-check forum

main
t 9 months ago
parent 7c1c9802c6
commit 67f05c4881

@ -0,0 +1,61 @@
import requests
from bs4 import BeautifulSoup
import telebot
from time import sleep
###### WORK WITH FILES #####
import pickle
def write(a_list):
with open('list', 'wb') as fp:
pickle.dump(a_list, fp)
def read():
with open('list', 'rb') as fp:
a_list = pickle.load(fp)
return a_list
############################
def check(bot, own_id):
response = requests.get("https://ss14top.404.mn/")
soup = BeautifulSoup(response.content, 'html.parser')
topics = []
for link in soup.find_all("a"):
link = str(link.get("href"))
if "topic" in link:
topics.append(link)
# Get only link to review below post
links = []
nums = [*range(1,15)]
for el in topics:
check = el[:el.rfind("/")]
if check not in links and check != "/topic/8/важное":
links.append(check)
############## CHECK IF MESSAGE NEW ############
for i in links:
response = requests.get(f"https://ss14top.404.mn/{i}")
soup = BeautifulSoup(response.content, 'html.parser')
# Add reviews and remove post (0)
reviews = []
for review in soup.find_all("div", class_="content"):
reviews.append(review.get_text())
reviews.pop(0)
# Check if new rev
old_reviews = read()
for rev in reviews:
if rev not in old_reviews:
new = f"{telebot.formatting.hcode(f'https://ss14top.404.mn/{i}')} \n\n{rev}"
bot.send_message(own_id, new, parse_mode="HTML")
# Write to reviews
reviews = old_reviews + reviews
write(reviews)
sleep(1)

@ -1,4 +1,3 @@
import telebot
from telebot import types,util
@ -69,5 +68,17 @@ def echo_message(message):
bot.reply_to(message, "Ваши данные отправлены на модерацию.\nПодождите, пожалуйста.")
# Check for new message on forum
from threading import Thread
from time import sleep
from check_new import *
def check_forum():
global own_id
while True:
check(bot, own_id)
sleep(60)
th = Thread(target=check_forum)
th.start()
bot.infinity_polling()

Loading…
Cancel
Save