-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegram_scraper_basic.py
64 lines (45 loc) · 1.48 KB
/
telegram_scraper_basic.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import functools
import threading
import telebot
from bs4_utils import Browser
from logger import logger
API_TOKEN = ""
bot = telebot.TeleBot(API_TOKEN)
class TelegramScrapper:
def __init__(self):
self.link_button = telebot.types.InlineKeyboardButton(text='More Info')
self.chat_id = None
self.browser = None
self.tele_scrapper = None
@staticmethod
def print_function_decorator(name):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
logger.info(f" Scraping ({name}) Started . . .")
func(*args, **kwargs)
logger.info(f" Scraping ({name}) Finished")
return wrapper
return decorator
# Button Callbacks handler
@bot.callback_query_handler(func=lambda call: True)
def callback(call):
timer_thread = None
if call.data == "":
timer_thread = threading.Thread(target=None)
timer_thread.start()
timer_thread.join()
# Command message handler
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.send_message(message.chat.id, 'Bot is Working .... be patient 🙏')
tele_scrapper.chat_id = message.chat.id
tele_scrapper.browser = Browser()
# Polling ...
def start_bot():
bot.polling()
if __name__ == '__main__':
tele_scrapper = TelegramScrapper()
logger.info("Please send /Start command in bot")
bot_thread = threading.Thread(target=start_bot, )
bot_thread.start()