Useful links:
Download Python
Download Tweepy
Using Twitter API & Installing Tweepy
Tweepy documentation
Related Topics:
These Twitter bot consists of several functions and methods that will help you to accomplish different tasks.

Tasks:

Find Users Using Keywords

In order to find the users who typed a keyword using this Twitter bot, simply call the "find" method; for example:

find("KEYWORD", "LANGUAGE", SINCE_DATE, UNTIL_DATE, WORDS_TO_OMIT_LIST, OMITTED_WORDS_FOUND_LIST, REPLIED_TO_USER_LIST, NUMBER_OF_RESULTS)

find("kanji", "en", "2017-8-22", "2017-9-22", omitList, foundOmitList, repliedUsernameList, 100)

In this case:
  • Search for keyword "kanji"
  • Make sure the tweet was typed in English
  • The tweet was posted during the last month
  • Retrieve only the first 100 tweets that matched the criteria
Data Flow Diagram



You can download the scripts here

Find Best Time To Tweet

To find the best time to tweet using this Twitter bot, simply call the "bestTimeToTweet" method; for example:

bestTimeToTweet(USERS_LIST, FUNCTION_TO_CALL, SAVED_TWEETS_TEMPORARY_LIST, SAVED_ALL_USER_TWEETS_LIST, SAVED_TWEETS_WITH_KEYWORDS_LIST, SAVED_TWEETS_TIMESTAMPS_LIST)

bestTimeToTweet(usernamesDict, getUserTweets, partialTweetsList, allTweetsList, retrieveTweetList, tweetsWeekdayTimesList)

In this case:
  • Retrieve all users' tweets
  • Save tweets that contain the desired keywords
  • Get the timestamp from each of the tweets that contained the keywords
  • Get the results sorted by the number of occurrences
Data Flow Diagram



You can download the scripts here

Find Who The Users You Follow Are Following

In order to find who the people you follow are following using this Twitter bot, simply call the "runReport" method; for example:

runReport("MY_USERNAME", USER_IDS_I_FOLLOW_LIST, USERNAMES_TO_FOCUS_ON_DICTIONARY, METHOD_TO_CALL, CURRENT_DATE)

runReport(myUsername, myIDsList, usernamesDict, report, "2017-9-22")

In this case:
  • Retrieve all user ids from people you follow
  • Find all user ids from users you specify
  • Get the number of followers from each of the users the users you specify are following
  • Find the date of the user's latest tweet
  • Get the usernames that matched the criteria
Data Flow Diagram



You can download the scripts here

Reply to tweets automatically

To reply to specific tweets automatically using this Twitter bot, simply call the "runBot" method; for example:

runBot(USERNAMES_TO_FOCUS_ON_DICTIONARY, METHOD_TO_CALL, SAVED_USERS_TEXT_FILE, SAVED_USERS_LIST)

runBot(usernamesDict, checkUsers, os.getcwd() + "\\saved_users.txt", savedUsersList)

In this case:
  • Retrieve the list of users you already replied to from text file
  • Get the tweets from users you specify
  • If the tweet matched the criteria, reply to tweet and save the username
  • Repeat the steps
*Note: Try to keep the text file's content for at least 2 weeks, some users might block your bot if you reply too frequently to their tweets.

Data Flow Diagram



You can download the scripts here

The following script (twitter_bot_specific_users) follows a "conservative approach" since the bot will only reply to the specific users you declared in the dictionary "usernamesDict" and will only follow accounts who are active and have at least 2,000 followers.

You can download the scripts here
Go to top
Go to top
Go to top
Go to top
The following script (twitter_bot_all_users) does not have any restrictions, the bot will reply to all of the users the account is following and it will follow all accounts regardless of number of followers and whether they are active or not.

You can download the scripts here
Read the following information in order to understand the whole process:

Step 1 - Download and install both, Python and Tweepy, and make sure you have a Twitter API. Watch this YouTube video to familiarize yourself with these concepts and the applications.

Step 2 - Download the scripts and place them in a folder.



Step 3 - Run either the "twitter_bot_specific_users" or the "twitter_bot_all_users" script.

The "saved_users" text file will store all of the users you are replying to.
Do not delete the text file's content after you are done running the script, do it after 2 weeks; otherwise, you will be replying to the same users every time you run the script.
web counter
Last Updated: September 22, 2017
© 2011-2017, Luis A. Hernandez
comments powered by Disqus