add feed modules

This commit is contained in:
2019-01-25 20:12:44 +03:00
parent ac925ee704
commit 6b085eee65
4 changed files with 67 additions and 1 deletions

21
feeds/modules/wp_comic.py Normal file
View File

@@ -0,0 +1,21 @@
import requests
from django.db import models
from telebot import TeleBot
from feeds.models import FeedModuleConfig
class WPComicFeedModuleConfig(FeedModuleConfig):
domain = models.URLField()
MODULE_NAME = 'WordPress comic'
def execute(self, bot: TeleBot, chat_id, last_id):
if last_id is None:
last_id = 0
media = requests.get('{}/wp-json/wp/v2/media'.format(self.domain.rstrip('/'))).json()
for m in filter(lambda x: x['id'] > last_id, reversed(media)):
bot.send_photo(chat_id, photo=m['source_url'], caption=m['title']['rendered'])
last_id = m['id']
return last_id