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)
|
||||||
|
|
Loading…
Reference in new issue