telegram_bots/feeds/modules/dank_memes.py
2021-03-20 16:21:13 +03:00

19 lines
674 B
Python

import requests
from telegram import Bot
from feeds.models import FeedModuleConfig
class DankMemesFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Dank memes (Reddit)'
def execute(self, bot: Bot, 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