telegram_bots/feeds/modules/wp_comic.py

21 lines
619 B
Python
Raw Normal View History

2019-01-25 17:12:44 +00:00
import requests
from django.db import models
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 WPComicFeedModuleConfig(FeedModuleConfig):
domain = models.URLField()
MODULE_NAME = 'WordPress comic'
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
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']