2019-01-25 16:33:22 +00:00
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
from django.conf import settings
|
2019-01-11 19:16:01 +00:00
|
|
|
from django.utils import timezone
|
|
|
|
from telebot import TeleBot
|
2019-01-19 06:52:00 +00:00
|
|
|
from djconfig import config
|
2019-01-11 19:16:01 +00:00
|
|
|
|
|
|
|
from config.celery import app
|
|
|
|
|
|
|
|
|
|
|
|
@app.task()
|
|
|
|
def execute_feed(feed_pk):
|
|
|
|
from feeds.models import Feed
|
2019-01-25 16:33:22 +00:00
|
|
|
from django.db import connections
|
|
|
|
|
|
|
|
c = connections['default'].cursor()
|
|
|
|
print(c.db.__dict__)
|
|
|
|
|
|
|
|
# config._reload_maybe()
|
2019-01-11 19:16:01 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
feed = Feed.objects.get(pk=feed_pk)
|
|
|
|
|
|
|
|
if not feed.lock:
|
|
|
|
feed.lock = True
|
|
|
|
feed.save()
|
|
|
|
|
2019-01-19 06:52:00 +00:00
|
|
|
bot = TeleBot(config.feed_bot_token)
|
2019-01-11 19:16:01 +00:00
|
|
|
feed.last_id = feed.config.execute(bot, feed.chat_id, feed.last_id)
|
|
|
|
feed.last_check = timezone.now()
|
|
|
|
feed.save()
|
|
|
|
finally:
|
|
|
|
feed.lock = False
|
|
|
|
feed.save()
|