Bot Utilities¶
The module bottr.util provides some functions that can be helpful when handling certain
situations while parsing comments or submission.
-
bottr.util.handle_rate_limit(func: typing.Callable[[typing.Any], typing.Any], *args, **kwargs) → typing.Any[source]¶ Calls
funcwith given arguments and handle rate limit exceptions.Parameters: - func – Function to call
- args – Argument list for
func - kwargs – Dict arguments for func
Returns: funcresult
-
bottr.util.check_comment_depth(comment: praw.models.reddit.comment.Comment, max_depth=3) → bool[source]¶ Check if comment is in a allowed depth range
Parameters: - comment –
praw.models.Commentto count the depth of - max_depth – Maximum allowed depth
Returns: True if comment is in depth range between 0 and max_depth
- comment –
-
bottr.util.get_subs(subs_file='subreddits.txt', blacklist_file='blacklist.txt') → typing.List[str][source]¶ Get subs based on a file of subreddits and a file of blacklisted subreddits.
Parameters: - subs_file – List of subreddits. Each sub in a new line.
- blacklist_file – List of blacklisted subreddits. Each sub in a new line.
Returns: List of subreddits filtered with the blacklisted subs.
Example files:
sub0 sub1 sub2 ...
-
bottr.util.init_reddit(creds_path='creds.props') → praw.reddit.Reddit[source]¶ Initialize the reddit session by reading the credentials from the file at
creds_path.Parameters: creds_path – Properties file with the credentials. Example file:
client_id=CLIENT_ID client_secret=CLIENT_SECRET password=PASSWORD user_agent=USER_AGENT username=USERNAME