update requirements, implement nerfnow feed
This commit is contained in:
parent
79a512784f
commit
fd63775d58
22
feeds/migrations/0008_nerfnowfeedmoduleconfig.py
Normal file
22
feeds/migrations/0008_nerfnowfeedmoduleconfig.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Generated by Django 2.1.5 on 2019-11-25 12:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('feeds', '0007_remove_feed_lock'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='NerfNowFeedModuleConfig',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
@ -6,8 +6,9 @@ from .shitty_watercolour import ShittyWatercolourFeedModuleConfig
|
|||||||
from .wp_comic import WPComicFeedModuleConfig
|
from .wp_comic import WPComicFeedModuleConfig
|
||||||
from .twitter import TwitterFeedModuleConfig
|
from .twitter import TwitterFeedModuleConfig
|
||||||
from .tapas import TapasFeedModuleConfig
|
from .tapas import TapasFeedModuleConfig
|
||||||
|
from .nerfnow import NerfNowFeedModuleConfig
|
||||||
|
|
||||||
FEED_MODULES = [EchoFeedModuleConfig, VKFeedModuleConfig, VKMusicFeedModuleConfig, DankMemesFeedModuleConfig,
|
FEED_MODULES = [EchoFeedModuleConfig, VKFeedModuleConfig, VKMusicFeedModuleConfig, DankMemesFeedModuleConfig,
|
||||||
ShittyWatercolourFeedModuleConfig, WPComicFeedModuleConfig, TwitterFeedModuleConfig,
|
ShittyWatercolourFeedModuleConfig, WPComicFeedModuleConfig, TwitterFeedModuleConfig,
|
||||||
TapasFeedModuleConfig]
|
TapasFeedModuleConfig, NerfNowFeedModuleConfig]
|
||||||
|
|
||||||
|
29
feeds/modules/nerfnow.py
Normal file
29
feeds/modules/nerfnow.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
import feedparser
|
||||||
|
from telebot import TeleBot
|
||||||
|
|
||||||
|
from feeds.models import FeedModuleConfig
|
||||||
|
|
||||||
|
|
||||||
|
IMAGE_RE = re.compile(r'<img alt=".+?" height=".+?" src="(.+?)" title')
|
||||||
|
CAPTION_RE = re.compile(r'<div>(<p>.*?</p>)</div>')
|
||||||
|
CAPTION_NEWLINE_RE = re.compile(r'(\w*<p>|</p>\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 = 0
|
||||||
|
|
||||||
|
feed = feedparser.parse('http://feeds.feedburner.com/nerfnow/full')
|
||||||
|
for e in reversed(feed['entries']):
|
||||||
|
if e['updated'] > 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))
|
||||||
|
caption = '<b>{}</b>\n\n{}\n\n{}'.format(e['title'], comment, e['feedburner_origlink'])
|
||||||
|
bot.send_photo(chat_id, url, caption, parse_mode='html')
|
||||||
|
yield e['updated']
|
@ -24,6 +24,7 @@ django-redis==4.10.0
|
|||||||
django-timezone-field==3.0
|
django-timezone-field==3.0
|
||||||
django-yamlfield==1.0.3
|
django-yamlfield==1.0.3
|
||||||
enum34==1.1.6
|
enum34==1.1.6
|
||||||
|
feedparser==5.2.1
|
||||||
future==0.17.1
|
future==0.17.1
|
||||||
idna==2.8
|
idna==2.8
|
||||||
json-rpc==1.12.1
|
json-rpc==1.12.1
|
||||||
@ -54,5 +55,5 @@ tornado==6.0.3
|
|||||||
urllib3==1.24.1
|
urllib3==1.24.1
|
||||||
uWSGI==2.0.17.1
|
uWSGI==2.0.17.1
|
||||||
vine==1.2.0
|
vine==1.2.0
|
||||||
vk-api==11.6.0
|
vk-api==11.6.1
|
||||||
Werkzeug==0.14.1
|
Werkzeug==0.14.1
|
||||||
|
Loading…
Reference in New Issue
Block a user