Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- import requests
- from time import sleep
- from telegram import Update
- from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
- TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'
- BOARD_URL = 'https://2ch.hk/b/'
- CHAT_ID = 'YOUR_CHAT_ID'
- logging.basicConfig(level=logging.INFO)
- def get_threads_with_min_posts(min_posts: int = 150):
- response = requests.get(BOARD_URL + 'threads.json')
- threads_data = response.json()['threads']
- result = []
- for thread in threads_data:
- if thread['posts_count'] >= min_posts:
- result.append(BOARD_URL + 'res/' + str(thread['thread_num']) + '.html')
- return result
- def check_threads(context: CallbackContext):
- threads = get_threads_with_min_posts()
- for thread in threads:
- if thread not in context.bot_data:
- context.bot.send_message(chat_id=CHAT_ID, text=f'Найден тред: {thread}')
- context.bot_data[thread] = True
- def main():
- updater = Updater(token=TOKEN, use_context=True)
- dp = updater.dispatcher
- jq = updater.job_queue
- jq.run_repeating(check_threads, interval=60, first=0)
- updater.start_polling()
- updater.idle()
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment