Skip to content

Commit

Permalink
Prevent operation blocking for twitter operation
Browse files Browse the repository at this point in the history
  • Loading branch information
heyrict committed Jun 9, 2018
1 parent e655b4b commit 4b42fdc
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions sui_hei/signals.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver
Expand All @@ -12,15 +14,20 @@
CONSUMER_SECRET = settings.CONSUMER_SECRET
TWEET_MESSAGE = settings.TWEET_MESSAGE

logger = logging.Logger(__name__)


@receiver(post_save, sender=Puzzle)
def add_twitter_on_puzzle_created(sender, instance, created, **kwargs):
if created and ENABLE_TWITTERBOT:
auth = OAuth(TOKEN, TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
t = Twitter(auth=auth)
t.statuses.update(
status=TWEET_MESSAGE % {
'user_nickname': instance.user.nickname,
'title': instance.title,
'id': instance.id
})
try:
auth = OAuth(TOKEN, TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
t = Twitter(auth=auth)
t.statuses.update(
status=TWEET_MESSAGE % {
'user_nickname': instance.user.nickname,
'title': instance.title,
'id': instance.id
})
except e:
logger.warning("Error update twitter status: %s" % e)

0 comments on commit 4b42fdc

Please sign in to comment.