def follow_trendy_users(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("** Following trendy users: **") trends = BotLogic.find_trending_topics_in_usa() BotLogic.find_users_to_follow_based_on_trend_list(trends) print("** Done Following trendy users... **") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def refresh_db(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print( 'Updating user-timeline & mentions DBs... This may take a few mins...' ) BotLogic.refresh_usertimeline_db() print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def retweet_trending_topics(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print( "Now, I'm searching for trending topics in the USA for posts to retweet..." ) usa_trends = BotLogic.find_trending_topics_in_usa() BotLogic.retweet_hashtags(usa_trends) print("**Done Retweeting...**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def unfollow_nonfollowers(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("Unfollowing those that don't me...") me = api.me().screen_name followers = BotLogic.get_my_followers() following = BotLogic.get_people_i_follow() BotLogic.unfollow_nonfollowers(followers, following) print("**Done unfollowing...**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def follow_back(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("Giving my followers the ol' follow back...") me = api.me().screen_name followers = BotLogic.get_my_followers() following = BotLogic.get_people_i_follow() BotLogic.follow_back(followers, following) print("**Done with 'Follow Back'**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def reply_to_mentions_and_follow(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("Replying to user's that have mentioned me and following them!") # Set all tweets that mention my user to list: mentions = api.mentions_timeline(tweet_mode='extended') following = BotLogic.get_people_i_follow() BotLogic.retweet_favorite_follow(mentions, following) print("**Done with mentions...**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def post_status(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") try: status = BotLogic.pick_status() api.update_status(status) print("-> Status posted!!!") except tweepy.TweepError as error: print("-> Couldn't update your status this time around.") print(f"-> Error: {error.reason}") pass print("**Done with Status...**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def retweet_my_hashtags(): hashtags = [ '#dc', '#sanfrancisco', '#la', '#ny', '#webdevelopment', '#skateboarding', '#WashingtonDC', '#sanfrancisco', '#losangeles', '#dmvmusic', '#coding', '#100daysofcode', '#dcrestaurant', '#sfrestaurant', '#larestaurant', '#nyrestaurant', '#gamedev', '#dcevents', '#sfevents', '#laevents', '#nyevents', '#dcnightlife', '#lanightlife', '#sfnightlife', '#nynightlife', '#ufc', '#gamingnews', '#newmusic', '#ustreetdc', ] print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("Now, I'm searching for hashtag posts to retweet...") BotLogic.retweet_hashtags(hashtags) BotLogic.find_users_to_follow_based_on_trend_list(hashtags) print("**Done Retweeting...**") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
def remove_old_tweets_from_timeline(): print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=") print("Picking a status from the list...") BotLogic.delete_old_tweets() print(f"≤≤≤ Done deleting tweets ≥≥≥") print("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=")
# ---------------------------------- Run Bot --------------------------------- # if __name__ == "__main__": print('|-|-|Configuring twitter-to-sqlite...|-|-|') TwitterBot.create_auth_json() sleep(10) while True: print("Twitter Bot Started!") print('┬─┬ノ( º _ ºノ)') TwitterBot.remove_old_tweets_from_timeline() print('(╯°□°)╯︵ ┻━┻') TwitterBot.refresh_db() TwitterBot.post_status() print('┬─┬ノ( ಠ ل͜ಠノ)') print("////-------Med Rest Period-------////") BotLogic.med_wait() TwitterBot.retweet_my_hashtags() print('(┛ಠ_ಠ)┛彡┻━┻') print("////-------Medium Rest Period-------////") BotLogic.med_wait() TwitterBot.follow_back() TwitterBot.post_status() print('┳━┳ ヽ(ಠل͜ಠ)ノ') print("////-------Medium Rest Period-------////") BotLogic.med_wait() TwitterBot.retweet_trending_topics() print('(╯°Д°)╯︵/(.□ . \)') print("////-------Medium Rest Period-------////") BotLogic.med_wait() TwitterBot.follow_trendy_users() TwitterBot.post_status()