pyTweetBot.config package¶
How to use the config package¶
Required fields¶
>>> required_fields = \
>>> {
>>> "database":
>>> {
>>> "host": {},
>>> "username": {},
>>> "password": {},
>>> "database": {}
>>> },
>>> "twitter":
>>> {
>>> "auth_token1": {},
>>> "auth_token2": {},
>>> "access_token1": {},
>>> "access_token2": {},
>>> "user": {}
>>> }
>>> }
Default configuration¶
>>> {
>>> "database" :
>>> {
>>> "host" : "",
>>> "username" : "",
>>> "password" : "",
>>> "database" : ""
>>> },
>>> "email" : "bot@bot.com",
>>> "scheduler" :
>>> {
>>> "sleep": [6, 13]
>>> },
>>> "hashtags":
>>> [
>>> ],
>>> "twitter" :
>>> "auth_token2" : "",
>>> "access_token1" : "",
>>> "access_token2" : "",
>>> "user" : ""
>>> },
>>> "friends" :
>>> {
>>> "max_new_followers" : 40,
>>> "max_new_unfollow" : 40,
>>> "follow_unfollow_ratio_limit" : 1.2,
>>> "interval" : [30, 45]
>>> },
>>> "forbidden_words" :
>>> [
>>> ],
>>> "direct_message" : "",
>>> "tweet" : {
>>> "max_tweets" : 1200,
>>> "exclude" : [],
>>> "interval" : [2.0, 4.0]
>>> },
>>> "news" :
>>> [
>>> {
>>> "keyword" : "",
>>> "countries" : ["us","fr"],
>>> "languages" : ["en","fr"],
>>> "hashtags" : []
>>> }
>>> ],
>>> "rss" :
>>> [
>>> {"url" : "http://feeds.feedburner.com/TechCrunch/startups", "hashtags" : "#startups", "via" : "@techcrunch"},
>>> {"url" : "http://feeds.feedburner.com/TechCrunch/fundings-exits", "hashtags" : "#fundings", "via" : "@techcrunch"}
>>> ],
>>> "max_retweets" : 600,
>>> "max_likes" : 600,
>>> "keywords" : [],
>>> "nbpages" : 40,
>>> "retweet_prob" : 0.5,
>>> "limit_prob" : 1.0
>>> "interval" : [2.0, 4.0]
>>> },
>>> "github" :
>>> {
>>> "login": "",
>>> "password": "",
>>> "exclude": [],
>>> "topics" : []
>>> }
>>> }
Construction¶
BotConfig class¶
-
class
pyTweetBot.config.
BotConfig
(data)¶ This class reads the JSON configuration file and check that all required field is set. It will check that a field a available when asked for or will raise a FieldNotAvailable exception.
- Arguments:
- data (dict): Configuration data as a dictionary.
-
database
¶ - Returns:
- Database configuration (username, password, database)
-
direct_message
¶ - Returns:
- Direct message configuration (dict)
-
email
¶ - Returns:
- Email address configuration (dict)
-
forbidden_words
¶ - Returns:
- Forbidden words configuration (dict)
-
friends
¶ - Returns:
- Friends configuration (dict)
-
get_current_interval
(setting)¶ Get the interval between actions for the current date and time.
- Arguments:
- setting (dict): The section containing interval data as a dictionary.
- Returns:
- A list (list) with the minimum and maximum time in seconds of the current interval.
-
get_random_interval
(setting)¶ Get a random waiting time for a specific type of actions.
- Arguments:
- setting (str): Setting type. Can be tweet, retweet, like, follow, unfollow
- Returns:
- A time interval as an integer corresponding to the time in seconds.
-
github
¶ - Returns:
- GitHub configuration (dict)
-
google_news
¶ - Returns:
- Google News configuration (dict)
- Returns:
- Hashtags configuration (dict)
-
is_available
(key)¶ Is a setting available in the loaded configuration?
- Arguments:
- key (str): Setting’s key in the configuration
-
is_awake
()¶ Is the scheduler awake or asleep?
- Returns:
- True if awake, False otherwise
-
static
load
(config_file)¶ Load the configuration file
- Arguments:
- config_file (str): Path to configuration file
- Returns:
- Bot configuration object of type
pyTweetBot.config.BotConfig
.
-
retweet
¶ - Returns:
- Retweet configuration (dict)
-
rss
¶ - Returns:
- RSS streams configuration (dict)
-
scheduler
¶ - Returns:
- Scheduler configuration (dict)
-
tweet
¶ - Returns:
- Tweet settings configuration (dict)
-
twitter
¶ - Returns:
- Twitter configuration (dict)
-
wait_next_action
(setting)¶ Wait for a random period corresponding to the current interval of an action type.
- Arguments:
- setting (dict): Setting type (tweet, retweet, friend) containing an interval field.