def sync(): profile = Profile.objects.filter(user__username='******').first() if profile is None: return last_tweet_id = Settings.last_tweet_id() timeline = t.get_timeline(since_id=last_tweet_id.value) timeline.reverse() count = 0 for tweet in timeline: weibo = tweet.to_weibo() if weibo is not None: result = oauth_weibo.post(profile, weibo) if result: last_tweet_id.value = weibo.tweet_id last_tweet_id.save() count += 1 seconds = random.randint(15, 45) time.sleep(seconds) logger.info(f'Tweets: Published. Sleep {seconds} seconds') logger.info(f'Cron job finished. Length: {len(timeline)}, sent: {count}')