import requests from telebot import TeleBot from feeds.models import FeedModuleConfig class DankMemesFeedModuleConfig(FeedModuleConfig): MODULE_NAME = 'Dank memes (Reddit)' def execute(self, bot: TeleBot, chat_id, last_id): posts = requests.get('https://www.reddit.com/r/dankmemes/top.json?sort=top&t=hour', headers={'User-agent': 'bakatrouble FeedBot 0.1'}).json() for p in posts['data']['children']: if p['kind'] == 't3' and 'post_hint' in p['data'] and p['data']['post_hint'] == 'image': p = p['data'] bot.send_photo(chat_id, p['url']) break yield None