add feed modules
This commit is contained in:
21
feeds/modules/wp_comic.py
Normal file
21
feeds/modules/wp_comic.py
Normal 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
|
Reference in New Issue
Block a user