Example #1
0
def main():
    all_blogs = get_blogs(rss_feed_url=BLOG_RSS_URL)
    update_blogs_database(all_blogs)
    blogs_to_tweet = get_relevant_blogs(all_blogs)
    products_to_tweet = get_site_products(product_url=PRODUCT_API_URL,
                                          num_products=TOTAL_NUM_TWEETS -
                                          len(blogs_to_tweet))
    twitter_api = setup_api()
    twitter_me = twitter_api.me()
    logger.info("Name: %s\nLocation: %s\nFriends: %s\nFollowers: %s\n",
                twitter_me.name, twitter_me.location, twitter_me.friends_count,
                twitter_me.followers_count)
    g = get_random_intervals(TOTAL_NUM_TWEETS)
    for post in np.random.permutation(blogs_to_tweet + products_to_tweet):
        interval = next(g)
        logger.info(
            f'Sleeping for {interval * NUM_HOURS * 3600: 0.2f} seconds')
        sleep(interval * NUM_HOURS * 3600)
        post.tweet(twitter_api)
Example #2
0
    "EnergieOverheid",
    "GroeneCourant",
    "TrouwGroen",
    "bnrduurzaam",
    "DuurzaamNieuws",
    "DuurzaamBV",
    "NatGeoPhotos",
    "SpaceX",
    "NatGeo",
    "NASA",
]

if __name__ == "__main__":
    logger = get_logger(home, "retweeter")
    logger.info("Setting up api connection...")
    api = setup_api(home)
    user = api.me()
    logger.info(
        "Name: {0}\nLocation: {1}\nFriends: {2}\nFollowers: {3}\n".format(
            user.name, user.location, user.friends_count,
            user.followers_count))
    while 1:
        now = arrow.now()
        new_tweets = get_tweets(api, relevant_accounts, logger)
        for tweet in new_tweets:
            try:
                logger.info("Retweeting: " + tweet.text)
                tweet_message = tweet.retweet()
                break
            except:
                continue