Guest User

Untitled

a guest
Mar 15th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. import logging
  2. import requests
  3. from time import sleep
  4. from telegram import Update
  5. from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
  6.  
  7. TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'
  8. BOARD_URL = 'https://2ch.hk/b/'
  9. CHAT_ID = 'YOUR_CHAT_ID'
  10.  
  11. logging.basicConfig(level=logging.INFO)
  12.  
  13. def get_threads_with_min_posts(min_posts: int = 150):
  14.     response = requests.get(BOARD_URL + 'threads.json')
  15.     threads_data = response.json()['threads']
  16.    
  17.     result = []
  18.    
  19.     for thread in threads_data:
  20.         if thread['posts_count'] >= min_posts:
  21.             result.append(BOARD_URL + 'res/' + str(thread['thread_num']) + '.html')
  22.    
  23.     return result
  24.  
  25. def check_threads(context: CallbackContext):
  26.     threads = get_threads_with_min_posts()
  27.    
  28.     for thread in threads:
  29.         if thread not in context.bot_data:
  30.             context.bot.send_message(chat_id=CHAT_ID, text=f'Найден тред: {thread}')
  31.             context.bot_data[thread] = True
  32.  
  33. def main():
  34.     updater = Updater(token=TOKEN, use_context=True)
  35.     dp = updater.dispatcher
  36.     jq = updater.job_queue
  37.    
  38.     jq.run_repeating(check_threads, interval=60, first=0)
  39.    
  40.     updater.start_polling()
  41.     updater.idle()
  42.  
  43. if __name__ == '__main__':
  44.     main()
  45.  
Add Comment
Please, Sign In to add comment