telegram_bots/feeds/modules/shitty_watercolour.py

24 lines
864 B
Python
Raw Normal View History

2019-01-25 17:12:44 +00:00
import requests
2021-03-20 13:21:13 +00:00
from telegram import Bot
2019-01-25 17:12:44 +00:00
from feeds.models import FeedModuleConfig
class ShittyWatercolourFeedModuleConfig(FeedModuleConfig):
MODULE_NAME = 'Shitty Watercolour (Reddit)'
2021-03-20 13:21:13 +00:00
def execute(self, bot: Bot, chat_id, last_id):
2019-01-25 17:12:44 +00:00
if last_id is None:
last_id = 0
posts = requests.get('https://www.reddit.com/user/Shitty_Watercolour.json',
headers={'User-agent': 'bakatrouble FeedBot 0.1'}).json()
for p in reversed(posts['data']['children']):
if p['data']['created'] > last_id and \
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'], p['title'])
2019-02-04 09:15:53 +00:00
yield p['created']