save last_id more often
This commit is contained in:
parent
0c0e63f545
commit
c1679c52a9
@ -3,7 +3,7 @@ from django.urls import path
|
|||||||
from .views import AggregationSourceListView, AggregationSourceCreateView, AggregationSourceUpdateView, \
|
from .views import AggregationSourceListView, AggregationSourceCreateView, AggregationSourceUpdateView, \
|
||||||
AggregationSourceDeleteView
|
AggregationSourceDeleteView
|
||||||
|
|
||||||
app_name = 'feeds'
|
app_name = 'aggregator'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', AggregationSourceListView.as_view(), name='index'),
|
path('', AggregationSourceListView.as_view(), name='index'),
|
||||||
path('<int:pk>/', AggregationSourceUpdateView.as_view(), name='edit'),
|
path('<int:pk>/', AggregationSourceUpdateView.as_view(), name='edit'),
|
||||||
|
@ -15,3 +15,4 @@ class DankMemesFeedModuleConfig(FeedModuleConfig):
|
|||||||
p = p['data']
|
p = p['data']
|
||||||
bot.send_photo(chat_id, p['url'])
|
bot.send_photo(chat_id, p['url'])
|
||||||
break
|
break
|
||||||
|
yield None
|
||||||
|
@ -11,3 +11,4 @@ class EchoFeedModuleConfig(FeedModuleConfig):
|
|||||||
|
|
||||||
def execute(self, bot: TeleBot, chat_id, last_id):
|
def execute(self, bot: TeleBot, chat_id, last_id):
|
||||||
bot.send_message(chat_id, self.message)
|
bot.send_message(chat_id, self.message)
|
||||||
|
yield None
|
||||||
|
@ -20,5 +20,4 @@ class ShittyWatercolourFeedModuleConfig(FeedModuleConfig):
|
|||||||
p['data']['post_hint'] == 'image':
|
p['data']['post_hint'] == 'image':
|
||||||
p = p['data']
|
p = p['data']
|
||||||
bot.send_photo(chat_id, p['url'], p['title'])
|
bot.send_photo(chat_id, p['url'], p['title'])
|
||||||
last_id = p['created']
|
yield p['created']
|
||||||
return last_id
|
|
||||||
|
@ -76,5 +76,4 @@ class VKFeedModuleConfig(FeedModuleConfig):
|
|||||||
disable_web_page_preview=True)
|
disable_web_page_preview=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sentry_sdk.capture_exception(e)
|
sentry_sdk.capture_exception(e)
|
||||||
last_id = post['id']
|
yield post['id']
|
||||||
return last_id
|
|
||||||
|
@ -66,5 +66,4 @@ class VKMusicFeedModuleConfig(FeedModuleConfig):
|
|||||||
f = get_file(track['url'], vk_session.http)
|
f = get_file(track['url'], vk_session.http)
|
||||||
bot.send_audio(chat_id, f, duration=track['duration'], performer=track['artist'],
|
bot.send_audio(chat_id, f, duration=track['duration'], performer=track['artist'],
|
||||||
title=track['title'])
|
title=track['title'])
|
||||||
last_id = track['id']
|
yield track['id']
|
||||||
return last_id
|
|
||||||
|
@ -17,5 +17,4 @@ class WPComicFeedModuleConfig(FeedModuleConfig):
|
|||||||
media = requests.get('{}/wp-json/wp/v2/media'.format(self.domain.rstrip('/'))).json()
|
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)):
|
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'])
|
bot.send_photo(chat_id, photo=m['source_url'], caption=m['title']['rendered'])
|
||||||
last_id = m['id']
|
yield m['id']
|
||||||
return last_id
|
|
||||||
|
@ -21,6 +21,7 @@ def execute_feed(feed_pk):
|
|||||||
|
|
||||||
config._reload_maybe()
|
config._reload_maybe()
|
||||||
|
|
||||||
|
feed = None
|
||||||
try:
|
try:
|
||||||
feed = Feed.objects.get(pk=feed_pk)
|
feed = Feed.objects.get(pk=feed_pk)
|
||||||
|
|
||||||
@ -29,9 +30,13 @@ def execute_feed(feed_pk):
|
|||||||
feed.save()
|
feed.save()
|
||||||
|
|
||||||
bot = TeleBot(config.feed_bot_token)
|
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.last_check = timezone.now()
|
||||||
feed.save()
|
feed.save()
|
||||||
finally:
|
finally:
|
||||||
feed.lock = False
|
if feed:
|
||||||
feed.save()
|
feed.lock = False
|
||||||
|
feed.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user