diff --git a/sui_hei/signals.py b/sui_hei/signals.py index ad53d4f..34c3318 100644 --- a/sui_hei/signals.py +++ b/sui_hei/signals.py @@ -1,3 +1,5 @@ +import logging + from django.conf import settings from django.db.models.signals import post_save from django.dispatch import receiver @@ -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)