puffotter package¶
Subpackages¶
Submodules¶
puffotter.crypto module¶
-
puffotter.crypto.
generate_hash
(password: str) → str¶ Salts and hashes a password to generate a hash for storage in a database :param password: The password to hash :return: The hash of the password
-
puffotter.crypto.
generate_random
(length: int) → str¶ Generates a random byte string consisting of alphanumeric characters Thanks @ Albert (https://stackoverflow.com/users/281021/albert) https://stackoverflow.com/questions/2257441 :param length: The length of the string to generate :return: The generated random byte string
-
puffotter.crypto.
verify_password
(password: str, hashed: str)¶ Verifies that a password matches a given hash :param password: The password to verify :param hashed: The hash to verify the password against :return: True if the password matches, otherwise False
puffotter.env module¶
-
puffotter.env.
load_env_file
(path: str = '.env')¶ Loads an environment file into os.environ :param path: The path to the environment file :return: None
puffotter.graphql module¶
-
class
puffotter.graphql.
GraphQlClient
(api_url: str)¶ Bases:
object
A simple API wrapper for GraphQL APIs
-
__init__
(api_url: str)¶ Initializes the GraphQL API wrapper :param api_url: The API endpoint URL
-
query
(query_string: str, variables: Optional[Dict[str, Any]]) → Optional[Dict[str, Any]]¶ Executes a GraphQL query :param query_string: The query string to use :param variables: The variables to send :return: The response JSON, or None if an error occurred.
-
puffotter.imap module¶
-
puffotter.imap.
get_inbox_count
(imap_server: str, imap_address: str, imap_password: str, imap_port: int = 993) → int¶ Checks the amount of emails in an IMAP inbox :param imap_server: The IMAP server to use :param imap_address: The IMAP address to use :param imap_password: The IMAP password to use :param imap_port: The IMAP port to use :return: The amount of emails
puffotter.init module¶
-
puffotter.init.
argparse_add_logfile
(parser: argparse.ArgumentParser)¶ Adds the –logfile argument to the argument parser :param parser: The argument parser to modify :return: None
-
puffotter.init.
argparse_add_verbosity
(parser: argparse.ArgumentParser)¶ Adds –quiet, –verbose and –debug parameters to an ArgumentParser :param parser: the parser to which to add those flags :return: None
-
puffotter.init.
cli_start
(main_func: Union[Callable[None], Callable[argparse.Namespace, None], Callable[[argparse.Namespace, logging.Logger], None]], arg_parser: argparse.ArgumentParser, exit_msg: str = 'Goodbye', package_name: Optional[str] = None, sentry_dsn: Optional[str] = None, release_name: Optional[str] = None)¶ Starts a program and sets up logging, as well as sentry error tracking :param main_func: The main function to call :param arg_parser: The argument parser to use :param exit_msg: The message printed when the program’s execution is
stopped using a keyboard interrupt
- Parameters
package_name – The package name of the application
sentry_dsn – The sentry DSN to use
release_name – The name of the release
- Returns
None
-
puffotter.init.
setup_logging
(args: argparse.Namespace, package_name: Optional[str])¶ Sets up logging for the provided arguments :param args: The CLI arguments :param package_name: The package name :return: None
puffotter.json module¶
-
puffotter.json.
jsonify_models
(data: Dict[str, Any], deep: bool = True) → Dict[str, Any]¶ Serializes a dictionary and calls the __json__() method on all objects that have one. :param data: The data to serialize :param deep: Indicates whether or not child models are included.
If False, only IDs will be included.
- Returns
The serialized data
puffotter.logging module¶
-
class
puffotter.logging.
ColorLogger
(logger: logging.Logger, debug_bg: str = '\x1b[47m', debug_fg: str = '\x1b[30m', info_bg: str = '\x1b[40m', info_fg: str = '\x1b[37m', warning_bg: str = '\x1b[43m', warning_fg: str = '\x1b[30m', error_bg: str = '\x1b[101m', error_fg: str = '\x1b[30m')¶ Bases:
object
-
__init__
(logger: logging.Logger, debug_bg: str = '\x1b[47m', debug_fg: str = '\x1b[30m', info_bg: str = '\x1b[40m', info_fg: str = '\x1b[37m', warning_bg: str = '\x1b[43m', warning_fg: str = '\x1b[30m', error_bg: str = '\x1b[101m', error_fg: str = '\x1b[30m')¶ Initialize self. See help(type(self)) for accurate signature.
-
debug
(message: str, bg: Optional[str] = None, fg: Optional[str] = None)¶ Logs a message at DEBUG level :param message: The message to log :param bg: Overrides the default background style :param fg: Overrides the default foreground style :return: None
-
error
(message: str, bg: Optional[str] = None, fg: Optional[str] = None)¶ Logs a message at ERROR level :param message: The message to log :param bg: Overrides the default background style :param fg: Overrides the default foreground style :return: None
-
info
(message: str, bg: Optional[str] = None, fg: Optional[str] = None)¶ Logs a message at INFO level :param message: The message to log :param bg: Overrides the default background style :param fg: Overrides the default foreground style :return: None
-
warning
(message: str, bg: Optional[str] = None, fg: Optional[str] = None)¶ Logs a message at WARNING level :param message: The message to log :param bg: Overrides the default background style :param fg: Overrides the default foreground style :return: None
-
puffotter.os module¶
-
puffotter.os.
create_file
(path: str)¶ Creates an empty file :param path: The path to the file :return: None
-
puffotter.os.
get_ext
(filename: str) → Optional[str]¶ Gets the file extension of a file :param filename: The filename for which to get the file extension :return: The file extension or None if the file has no extension
-
puffotter.os.
listdir
(path: str, no_files: bool = False, no_dirs: bool = False, no_dot: bool = True) → List[Tuple[str, str]]¶ Improves on the standard os.listdir function. By default, files and directories starting with . are ignored and one can disable checking for files or directories. Instead of just the filenames, the function returns tuples of filenames and relative file paths. :param path: The path of which to list the contents :param no_files: If set to True, will ignore files :param no_dirs: If set to True, will ignore directories :param no_dot: If set to True, will ignore files starting with . :return: A sorted list of the contents of the directory, consisting of
tuples of the file/directory name and their relative path.
-
puffotter.os.
makedirs
(path: str, delete_before: bool = False)¶ A more pleasant to use makedirs function. Only calls os.makedirs if the directory does not already exist :param path: The path to the directory to create :param delete_before: If True, deletes the directory beforehand,
if it exists
- Returns
None
-
puffotter.os.
replace_illegal_ntfs_chars
(string: str) → str¶ Replaces illegal characters in NTFS file systems with appropriate substitutes :param string: Te string in which to replace the illegal characters :return: The sanitized string
-
puffotter.os.
touch
(path: str)¶ Ensures that a file exists :param path: Path to the file to ensure it exists
puffotter.print module¶
-
puffotter.print.
pprint
(*objects: str, sep: str = ' ', end: str = '\n', file: IO = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, flush: bool = False, fg: Optional[str] = None, bg: Optional[str] = None)¶ Function that extends the print function :return: None
puffotter.prompt module¶
-
puffotter.prompt.
prompt
(prompt_text: str = '', default: Optional[Any] = None, _type: Callable[str, Any] = <class 'str'>, required: bool = True, choices: Optional[Set[str]] = None) → Optional[Any]¶ Generic prompt with configuration options :param prompt_text: The text to display before the prompt :param default: A default value to use if the user responds with ‘’ :param _type: The type of the object prompted. Must take a single string
as a parameter
- Parameters
required – Whether or not a response is required
choices – Valid choices for the prompt
- Returns
The prompt result. May be None if required is False
-
puffotter.prompt.
prompt_comma_list
(message: str, primitive_type: Callable[str, Any] = <class 'str'>, min_count: int = 0, no_empty: bool = True, default: Optional[List[Any]] = None) → List[Any]¶ Prompts the user for a comma-separated list :param message: The message to display :param primitive_type: The primitive type of the elements in the list :param min_count: The minimum amount of elements to be provided by the user :param no_empty: Removes any empty strings :param default: A default value :return: The result of the prompt
-
puffotter.prompt.
selection_prompt
(objects: List[object]) → List[object]¶ Prompts the user for a selection from a list of objects :param objects: The objects to show :return: The selection of objects
-
puffotter.prompt.
yn_prompt
(message: str, make_sure: bool = True, case_sensitive: bool = False) → bool¶ Creates a yes/no prompt :param message: The message to display :param make_sure: Continuously prompts if the response is neither
‘y’ or ‘n’ until it is. If false, every input besides ‘y’ will result in the return value being False
- Parameters
case_sensitive – Whether or not the prompt should be case-sensitive
- Returns
True if the user specified ‘y’, else False
puffotter.recaptcha module¶
-
puffotter.recaptcha.
verify_recaptcha
(client_ip: str, recaptcha_response: str, secret_key: str) → bool¶ Verifies a recaptcha response. If the recaptcha response originates from a local address, this method will always return True. :param client_ip: The IP Address of the client solving the captcha :param recaptcha_response: the recaptcha response to verify :param secret_key: the recaptcha secret key :return: True if the recaptcha response was correct, False otherwise
puffotter.requests module¶
-
puffotter.requests.
aggressive_request
(url: str) → str¶ Handles GET requests while analyzing status codes :param url: The URL to get :return: The response text
puffotter.smtp module¶
-
puffotter.smtp.
send_email
(address: str, title: str, message: str, smtp_server: str, smtp_address: str, smtp_password: str, smtp_port: int = 587)¶ Sends an HTML email message using SMTP :param address: The address to send to :param title: The email’s title :param message: The message to send :param smtp_server: The SMTP server to use :param smtp_address: The SMTP address to use :param smtp_password: The SMTP password to use :param smtp_port: The SMTP port to use :return: None
puffotter.subprocess module¶
-
puffotter.subprocess.
execute_command
(command: List[str]) → int¶ Executes a command :param command: The command to execute :return: The status code
puffotter.testutils module¶
puffotter.units module¶
-
puffotter.units.
byte_string_to_byte_count
(byte_string: str) → int¶ Converts a string representing bytes to a number of bytes. For example: “500K” -> 500 000
“2.5M” -> 2 500 000 “10GB” -> 10 000 000 000 “30kb/s” -> 30 000
- Parameters
byte_string – The string to convert
- Returns
The amount of bytes
-
puffotter.units.
human_readable_bytes
(bytecount: int, base_1024: bool = False, remove_trailing_zeroes: bool = True) → str¶ Converts an amount of bytes into a human-readable string :param bytecount: The bytes to convert :param base_1024: Whether or not to use 1024 as base (for mebibytes etc) :param remove_trailing_zeroes: If set to True, will remove any trailing
zeroes from the string
- Returns
The human-readable string