Last active
January 11, 2021 13:07
-
-
Save andriyor/d190defa0ba79fc92b03dbb5e6b3caf8 to your computer and use it in GitHub Desktop.
instantviw-new-item
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import schedule | |
import time | |
import telebot | |
import requests | |
from bs4 import BeautifulSoup | |
from mongoengine import connect, Document, StringField | |
token = 'token' | |
bot = telebot.TeleBot(token) | |
connect('telegram_url') | |
class Telegram(Document): | |
url = StringField() | |
author = StringField() | |
def job(): | |
r = requests.get('https://instantview.telegram.org/contest') | |
soup = BeautifulSoup(r.text, "html.parser") | |
item = soup.findAll("div", {"class": "list-group-contest-item"}) | |
l = [i.url for i in Telegram.objects] | |
for i in item[1:]: | |
domain = i.find("div", {"class": "contest-item-domain"}) | |
author = i.find("span", {"class": "contest-item-cell contest-item-candidate"}) | |
try: | |
author = author.findAll("a")[1].text | |
except IndexError: | |
author = None | |
if domain.a.text not in l: | |
Telegram(url=domain.a.text, author=author).save() | |
bot.send_message('user_id', domain.a.text) | |
schedule.every(10).minutes.do(job) | |
while True: | |
schedule.run_pending() | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment