import re from datetime import datetime import feedparser from telebot import TeleBot from telegram.constants import MAX_CAPTION_LENGTH from feeds.models import FeedModuleConfig IMAGE_RE = re.compile(r'(
.*?
)') CAPTION_NEWLINE_RE = re.compile(r'(\w*|
\w*){1,2}') class NerfNowFeedModuleConfig(FeedModuleConfig): MODULE_NAME = 'NerfNow.com' def execute(self, bot: TeleBot, chat_id, last_id): if last_id is None: last_id = '' feed = feedparser.parse('http://feeds.feedburner.com/nerfnow/full') for e in reversed(feed['entries']): if e['feedburner_origlink'] > last_id: data = e['content'][0]['value'].replace('\n', '') url = IMAGE_RE.search(data).group(1).replace('/large', '') comment = CAPTION_NEWLINE_RE.sub('\n', CAPTION_RE.search(data).group(1)) comment = comment.replace('