add feed modules
This commit is contained in:
24
feeds/modules/shitty_watercolour.py
Normal file
24
feeds/modules/shitty_watercolour.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import requests
|
||||
from telebot import TeleBot
|
||||
|
||||
from feeds.models import FeedModuleConfig
|
||||
|
||||
|
||||
class ShittyWatercolourFeedModuleConfig(FeedModuleConfig):
|
||||
MODULE_NAME = 'Shitty Watercolour (Reddit)'
|
||||
|
||||
def execute(self, bot: TeleBot, chat_id, last_id):
|
||||
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'])
|
||||
last_id = p['created']
|
||||
return last_id
|
Reference in New Issue
Block a user