save last_id more often

master
bakatrouble 5 years ago
parent 0c0e63f545
commit c1679c52a9

@ -3,7 +3,7 @@ from django.urls import path
from .views import AggregationSourceListView, AggregationSourceCreateView, AggregationSourceUpdateView, \
AggregationSourceDeleteView
app_name = 'feeds'
app_name = 'aggregator'
urlpatterns = [
path('', AggregationSourceListView.as_view(), name='index'),
path('<int:pk>/', AggregationSourceUpdateView.as_view(), name='edit'),

@ -15,3 +15,4 @@ class DankMemesFeedModuleConfig(FeedModuleConfig):
p = p['data']
bot.send_photo(chat_id, p['url'])
break
yield None

@ -11,3 +11,4 @@ class EchoFeedModuleConfig(FeedModuleConfig):
def execute(self, bot: TeleBot, chat_id, last_id):
bot.send_message(chat_id, self.message)
yield None

@ -20,5 +20,4 @@ class ShittyWatercolourFeedModuleConfig(FeedModuleConfig):
p['data']['post_hint'] == 'image':
p = p['data']
bot.send_photo(chat_id, p['url'], p['title'])
last_id = p['created']
return last_id
yield p['created']

@ -76,5 +76,4 @@ class VKFeedModuleConfig(FeedModuleConfig):
disable_web_page_preview=True)
except Exception as e:
sentry_sdk.capture_exception(e)
last_id = post['id']
return last_id
yield post['id']

@ -66,5 +66,4 @@ class VKMusicFeedModuleConfig(FeedModuleConfig):
f = get_file(track['url'], vk_session.http)
bot.send_audio(chat_id, f, duration=track['duration'], performer=track['artist'],
title=track['title'])
last_id = track['id']
return last_id
yield track['id']

@ -17,5 +17,4 @@ class WPComicFeedModuleConfig(FeedModuleConfig):
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
yield m['id']

@ -21,6 +21,7 @@ def execute_feed(feed_pk):
config._reload_maybe()
feed = None
try:
feed = Feed.objects.get(pk=feed_pk)
@ -29,9 +30,13 @@ def execute_feed(feed_pk):
feed.save()
bot = TeleBot(config.feed_bot_token)
feed.last_id = feed.config.execute(bot, feed.chat_id, feed.last_id)
for last_id in feed.config.execute(bot, feed.chat_id, feed.last_id):
if last_id:
feed.last_id = last_id
feed.save()
feed.last_check = timezone.now()
feed.save()
finally:
feed.lock = False
feed.save()
if feed:
feed.lock = False
feed.save()

Loading…
Cancel
Save