telegram_bots/feeds/modules/wp_comic.py

21 lines
626 B
Python
Raw Normal View History

2019-01-25 17:12:44 +00:00
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'])
2019-02-04 09:15:53 +00:00
yield m['id']