telegram_bots/feeds/modules/dank_memes.py

18 lines
662 B
Python
Raw Normal View History

2019-01-25 17:12:44 +00:00
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