pyTweetBot submodules¶
Submodules¶
pyTweetBot.execute_actions module¶
-
pyTweetBot.execute_actions.
execute_actions
(config, action_scheduler, no_tweet=False, no_retweet=False, no_like=False, no_follow=False, no_unfollow=False)¶ Launch threads that will execute each action thread.
- Examples:
>>> config = BotConfig.load("config.json") >>> action_scheduler = ActionScheduler(config=config) >>> execute_actions(config, action_scheduler)
- Arguments:
- config (BotConfig): Bot configuration of type
pyTweetBot.config.BotConfig
. - action_scheduler (ActionScheduler): Action management of type
pyTweetBot.executor.ActionScheduler
- no_tweet (Boolean): Do not execute tweet action
- no_retweet (Boolean): Do not execute retweet action
- no_like (Boolean): Do not execute like action
- no_follow (Boolean): Do not execute follow action
- no_unfollow (Boolean): Do not execute unfollow action
- config (BotConfig): Bot configuration of type
pyTweetBot.export_database module¶
-
pyTweetBot.export_database.
export_database
(output_dir, mysql_connector)¶ Export a database from a MySQL database to a series of files.
- Example:
>>> mysql_connector = DBConnector(host="localhost", username="test", password="pass", db_name="pytb") >>> export_database(".", mysql_connector)
- Arguments:
- output_dir (str): The output directory path
- mysql_connector (DBConnector) : A connector object of type
pyTweetBot.db.DBConnector
pyTweetBot.find_follows module¶
-
pyTweetBot.find_follows.
add_follow_action
(action_scheduler, friend)¶ Add a follow action through the scheduler.
- Arguments:
- action_scheduler (ActionScheduler): An action scheduler objet of type
pyTweetBot.executor.ActionScheduler
- friend (Friend of tweepy.User): A friend object (
pyTweetBot.db.obj.Friend
) or a tweepy.User object.
- action_scheduler (ActionScheduler): An action scheduler objet of type
-
pyTweetBot.find_follows.
find_follows
(config, model, action_scheduler, friends_manager, text_size, n_pages=20, threshold=0.5)¶ Find Twitter user to follows accordingly to parameters set in the config file.
- Example:
>>> config = BotConfig.load("config.json") >>> find_follows(config, model, action_scheduler, friends_manager, 50)
- Arguments:
- config: Bot’s configuration object
- model: Classification model’s file
- action_scheduler: Action scheduler object
- friends_manager: Friends manager object
- text_size: Minimum text size to be accepted
- n_pages: Number of pages to search for each term
- threshold: Minimum probability to accept following
pyTweetBot.find_github_tweets module¶
-
pyTweetBot.find_github_tweets.
add_tweet
(action_scheduler, tweet_text)¶ Add tweet through the scheduler
- Arguments:
- action_scheduler: The action scheduler object
- tweet_text: Text to tweet
- Returns:
- True if ok, False if problem.
-
pyTweetBot.find_github_tweets.
compute_tweet
(tweet_text, action_scheduler, instantaneous)¶ Tweet something directly or add it to the database.
- Arguments:
- tweet_text (unicode): The text to tweet.
- action_scheduler (ActionScheduler): Action scheduler object of type (
pyTweetBot.executor.ActionScheduler
) - instantaneous (bool): Tweet directly (True) or add it to the DB.
- Returns:
- True if tweeted/added, False if already in the database.
-
pyTweetBot.find_github_tweets.
create_tweet_text
(contrib_counter, contrib_date, project_name, project_url, topics)¶ Create the tweet’s text for a git push event.
- Arguments:
- contrib_counter (int): Number of contributions
- contrib_date (datetime): Date of the push
- project_name (unicode): GitHub project’s name
- project_url (str): GitHub project’s URL
- topics (list): GitHub project’s topics
- Returns:
- The tweet’s text.
-
pyTweetBot.find_github_tweets.
create_tweet_text_create
(project_name, project_description, project_url, topics)¶ Create tweet’s text for a git repository creation.
- Arguments:
- project_name (unicode): GitHub project’s name
- project_description (unicode): GitHub project’s description
- project_url (unicode): GitHub project’s URL
- topics (list): GitHub project’s topics.
- Returns:
return: The created text.
-
pyTweetBot.find_github_tweets.
find_github_tweets
(config, action_scheduler, event_type='push', depth=-1, instantaneous=False, waiting_time=0)¶ Add tweets based on GitHub activities to the database, or tweet it directly.
- Arguments:
- config (BotConfig): Bot config object of type
pyTweetBot.config.BotConfig
- action_scheduler (ActonScheduler): Action scheduler object of type
pyTweetBot.executor.ActionScheduler
- event_type (str): Type of event to tweet (push or create)
- depth (int): Number of events to tweet for each repository.
- instantaneous: Tweet the information instantaneously or not (to DB)?
- waiting_time: Waiting time between each tweets (for instantaneous tweeting)
- config (BotConfig): Bot config object of type
-
pyTweetBot.find_github_tweets.
prepare_project_name
(project_name)¶ Replace - by space in the project name and put the first letter of each word to uppercase.
- Arguments:
- project_name (unicode): GitHub project’s name
- Returns:
- The cleaned project name
pyTweetBot.find_retweets module¶
-
pyTweetBot.find_retweets.
find_retweets
(config, model_file, action_scheduler, text_size=80, threshold=0.5)¶ Find tweets to retweet from search terms set in the config file.
- Example:
>>> config = BotConfig.load("config.json") >>> action_scheduler = ActionScheduler(config=config) >>> find_retweets(config, "model.p", action_scheduler)
- Arguments:
- config (BotConfig): Bot configuration object of type
pyTweetBot.config.BotConfig
- model_file (str): Path to the file containing the classifier model
- action_scheduler (ActionScheduler): Action scheduler object of type
pyTweetBot.executor.ActionScheduler
- text_size (int): Minimum text length to take a tweet into account
- threshold (float): Minimum to reach to be classified as positive
- config (BotConfig): Bot configuration object of type
pyTweetBot.find_tweets module¶
-
pyTweetBot.find_tweets.
find_tweets
(config, model_file, action_scheduler, n_pages=2, threshold=0.5)¶ Find tweet from Google News and RSS streams.
- Examples:
>>> config = BotConfig.load("config.json") >>> action_scheduler = ActionScheduler(config=config) >>> find_tweets(config, "model.p", action_scheduler)
- Arguments:
- config (BotConfig): BotConfig configuration object of type
pyTweetBot.config.BotConfig
- model_file (str): Path to model file for classification
- action_scheduler (ActionScheduler): Scheduler object of type
pyTweetBot.executor.ActionScheduler
- n_pages (int): Number of pages to analyze
- threshold (float): Probability threshold to be accepted as tweet
- config (BotConfig): BotConfig configuration object of type
pyTweetBot.find_unfollows module¶
-
pyTweetBot.find_unfollows.
find_unfollows
(config, friends_manager, model_file, action_scheduler, threshold=0.5)¶ Find Twitter users to unfollow according to the parameters in the configuration file.
- Example:
>>> config = BotConfig.load("config.json") >>> action_scheduler = ActionScheduler(config=config) >>> friends_manager = FriendsManager() >>> find_unfollows(config, friends_manager, "model.p", action_scheduler)
- Arguments:
- config (BotConfig): Bot configuration object of type
pyTweetBot.config.BotConfig
- friends_manager (FriendsManager): Friend manager object of type
pyTweetBot.friends.FriendsManager
- model_file (str): Path to the model’s Pickle file.
- action_scheduler (ActionScheduler): Action scheduler object.
- threshold (float): Probability threshold to accept unfollow.
- config (BotConfig): Bot configuration object of type
pyTweetBot.follower_dataset module¶
-
pyTweetBot.follower_dataset.
follower_dataset
(twitter_connect, dataset_file, info, source='followers', text_size=50)¶ Create a dataset or add textual data from a list of Twitter users.
- Example:
>>> config = BotConfig.load("config.json") >>> twitter_connector = TweetBotConnector(config) >>> follower_dataset(twitter_connect, "dataset.p", False, 'followers')
- Arguments:
- twitter_connect (TweetBotConnector): Twitter bot connector object of type
pyTweetBot.twitter.TweetBotConnect
- dataset_file (str): Path to the dataset file to load or create.
- info (bool): If True, show information about the dataset and exit
- source (str): Can be ‘follower’ or ‘following’. Set where to load users from.
- text_size (int): Minimum user’s description length to take the profile into account.
- twitter_connect (TweetBotConnector): Twitter bot connector object of type
pyTweetBot.import_database module¶
-
pyTweetBot.import_database.
import_actions
(session, actions)¶ Import actions :param session: :param actions: :return:
-
pyTweetBot.import_database.
import_database
(output_dir, mysql_connector)¶ Function to import the database :param output_dir: :param mysql_connector: :return:
-
pyTweetBot.import_database.
import_friends
(session, friends)¶ Import friends :param session: :param friends: :return:
-
pyTweetBot.import_database.
import_statistics
(session, statistics)¶ Import statistics :param session: :param statistics: :return:
-
pyTweetBot.import_database.
import_tweets
(session, tweets)¶ Import tweets :param session: :param tweets: :return:
pyTweetBot.list_actions module¶
-
pyTweetBot.list_actions.
list_actions
(action_scheduler, action_type='')¶ List actions :param action_scheduler: Action Scheduler object :param action_type: Filter action type
pyTweetBot.model_testing module¶
-
pyTweetBot.model_testing.
model_testing
(data_set_file, model_file, text_size=2000, threshold=0.5)¶ Test a classifier :param data_set_file: Path to the dataset file :param model_file: Path to model file if needed :param text_size: Minimum text size :param threshold: Probability threshold
pyTweetBot.model_training module¶
-
pyTweetBot.model_training.
model_training
(data_set_file, model_file='', model_type='NaiveBayes')¶ Train a classifier on a dataset. :param data_set_file: Path to the dataset file :param model_file: Path to model file if needed :param model_type: Model’s type (stat, tfidf, stat2, textblob)
pyTweetBot.retweet_dataset module¶
-
pyTweetBot.retweet_dataset.
retweet_dataset
(config, dataset_file, search='', info=False, source='tweets')¶ Get retweet data :param config: :param dataset_file: :param n_pages: :param search: Search term :param info: :return:
pyTweetBot.statistics_generator module¶
-
pyTweetBot.statistics_generator.
statistics_generator
(twitter_connector, stats_file, n_pages, stream, info)¶ Statistics generator
pyTweetBot.tweet_dataset module¶
-
pyTweetBot.tweet_dataset.
tweet_dataset
(config, dataset_file, n_pages, info, rss)¶ Create a tweet dataset :param config: :param tweet_connector: :return:
pyTweetBot.tweet_training module¶
-
pyTweetBot.tweet_training.
clean_html_text
(to_clean)¶ Clean HTML text :param to_clean: :return:
-
pyTweetBot.tweet_training.
tweet_training
(dataset_file, model_file='', test=False, param='dp', type='stat')¶ Train a classifier on a dataset. :param config: pyTweetBot configuration object :param dataset_file: Path to the dataset file :param model_file: Path to model file if needed :param data: Title or content :param test: Test the classification success rate :param param: Model parameter (dp, …) :param type: Model’s type (stat, tfidf, stat2, textblob)
pyTweetBot.unfollow_dataset module¶
pyTweetBot.update_statistics module¶
-
pyTweetBot.update_statistics.
update_statistics
(config)¶ Update the statistics in the DB :param config: :return: