Exemplo n.º 1
0
    def handle(self, *args, **options):

        consumer_key = ''
        consumer_secret = ''
        access_token = ''
        access_token_secret = ''

        api = authenticate(consumer_key, consumer_secret, access_token,
                           access_token_secret)

        arw = arrow.utcnow()
        from_time = arw.shift(hours=-1).datetime
        to_time = timezone.now()

        scheduled_tweets = ScheduledTweet.objects.filter(
            published=False).filter(scheduled_for__gte=from_time).filter(
                scheduled_for__lte=to_time)

        if scheduled_tweets:
            for scheduled_tweet in scheduled_tweets:
                successful = update_status(api, scheduled_tweet.tweet.content)
                if successful:
                    scheduled_tweet.published = True
                    scheduled_tweet.save()
                    logger.info(
                        f'Published scheduled tweet with pk: {scheduled_tweet.pk}'
                    )
                else:
                    logger.error(
                        f'Error publishing scheduled tweet with pk: {scheduled_tweet.pk}'
                    )

        logger.info('publish scheduled tweets command ran successfully')
    def handle(self, *args, **options):

        consumer_key = ''
        consumer_secret = ''
        access_token = ''
        access_token_secret = ''

        api = authenticate(consumer_key, consumer_secret, access_token,
                           access_token_secret)

        arw = arrow.utcnow()
        from_time = arw.shift(hours=-1).datetime
        to_time = timezone.now()

        scheduled_tweets = ScheduledTweet.objects.filter(
            published=False).filter(scheduled_for__gte=from_time).filter(
                scheduled_for__lte=to_time)

        if scheduled_tweets:
            for scheduled_tweet in scheduled_tweets:
                successful = update_status(api, scheduled_tweet.tweet.content)
                if successful:
                    scheduled_tweet.published = True
                    scheduled_tweet.save()
                    # log success
                else:
                    pass
                    # log errors
            # log job ran and published tweets
        else:
            pass
Exemplo n.º 3
0
 def test_twitter_authenticate_returns_true(self, mocko):
     self.assertTrue(authenticate(self.consumer_key,self.consumer_secret,self.access_token,self.access_token_secret))