WiFi Pineapple Python Module
Table of contents
Introduction
Python API
Classes
class Module
Methods
def __init__(self, name: str, log_level: int = logging.WARNING):
Parameters
- name: The name of the module.
- The level of logging you wish to show. Default WARNING
Returns
- Optional[Job]: an instance of Job if found, else None
def shutdown(self, sig=None, frame=None)
def start(self)
def register_action_handler(self, action: str, handler: Callable[[Request], Union[Any, Tuple[Any, bool]]])
Usage Example: module = Module('example') def save_file(request: Request) -> Union[Any, Tuple[Any, bool]]: ... module.register_action_handler(save_file)
Parameters
- action: The request action to handle
- handler: A function that takes `Request` that gets called when the matching `action` is received.
def handles_action(self, action: str)
Example Function: @handles_action('save_file') def save_file(request: Request) -> str: ... return 'Filed saved successfully!' Example Response: { "payload": "File saved successfully!" }
If a tuple is returned, the first value in the tuple will the data sent back to the user. The second value must be a boolean that indicates whether the function was successful (True) or not (False). If this value is True, the data in the first index will be sent back in the response payload.
Example Function: @handles_action('save_file') def save_file(request: Request) -> Tuple[str, bool]: ... return 'Filed saved successfully!', True Example Response: { "payload": "File saved successfully!" }
However, if this value is False, The data in the first index will be sent back as an error.
Example Function: @handles_action('save_file') def save_file(request: Request) -> Tuple[str, bool]: ... return 'There was an issue saving the file.', False Example Response: { "error": There was an issue saving the file." }
Parameters
- action: The request action to handle
def register_shutdown_handler(self, handler: Callable[[Optional[int]], None])
Example: module = Module('example') def stop_all_tasks(signal: int): ... module.register_shutdown_handler(stop_all_tasks)
Parameters
- handler: A function to be called on shutdown lifecycle event.
def on_shutdown(self)
Example: @module.on_shutdown() def stop_all_tasks(signal: int): ...
def register_startup_handler(self, handler: Callable[[Optional[int]], None])
Example: module = Module('example') def copy_configs(): ... module.register_startup_handler(copy_configs)
Parameters
- handler: A function to be called on shutdown lifecycle event.
def on_start(self)
Example: @module.on_start() def copy_configs(): ...
def send_notification(self, message: str, level: int) -> bool
Parameters
- message: Notification message
- level: Notification level