ntfy_wrapper.utils

A module containing utility functions for ntfy-wrapper.

Module Contents

Functions

code(value)

Turns an object into a string and wraps it in a rich code block.

generate_topic()

Generate a cryptographically secure topic id using xkcdpass.

get_conf_path([conf_path])

Finds a path to the configuration file.

load_conf([conf_path])

Loads a config file from the given path.

write_conf(conf_path, conf)

Write the configuration file as an INI file.

Attributes

DOCSTRING

KEYS

custom_theme

print

ntfy_wrapper.utils.DOCSTRING = Multiline-String
Show Value
 1This INI config file contains 2 sections:
 2[notifier_init], and [notify_defaults].
 3Values in [notifier_init] can be strings or lists of strings (comma separated).
 4Values in [notify_defaults] can be best understood from the ntfy documentation:
 5https://ntfy.sh/docs/publish/
 6⚠️
 7Nota Bene: a 'topic' is kind of a password: anyone with The topic id can send messages
 8to your device, so protect it and make sure to remove this config file from the version
 9control system.
1011Example:
12-----------------------------------------------------------------------------------------
13# For Notifier(emails=..., topics=...)
14[notifier_init]
15topics = my-secret-topic-1, mysecrettopic2
16emails = you@foo.bar
17base_url = https://ntfy.your-server.io
18
19# For Notifier.notify(title=..., priority=..., etc.)
20[notify_defaults]
21title = Message from ntfy-wrapper
22priority = 0
23tags = fire
24click =
25attach =
26actions =
27icon = https://raw.githubusercontent.com/vict0rsch/ntfy-wrapper/main/assets/logo.png
28----------------------------------------------------------------------------------------
ntfy_wrapper.utils.KEYS
ntfy_wrapper.utils.code(value)

Turns an object into a string and wraps it in a rich code block. A pathlib Path will be shortened to the 3 last parts of the path.

Parameters

value (Any) – Object to convert to string and wrap in a rich code block.

Returns

Code-wrapped value: [code]{str(value)}[/code]

Return type

str

ntfy_wrapper.utils.custom_theme
ntfy_wrapper.utils.generate_topic()

Generate a cryptographically secure topic id using xkcdpass. See https://xkcd.com/936/ for illustration

Returns

dash-separated topic id

Return type

str

ntfy_wrapper.utils.get_conf_path(conf_path=None)

Finds a path to the configuration file. If a directory is provided, the config file will be named “.ntfy.conf” If the path is not provided, it will look for the file in the current working directory,

Parameters

conf_path (Optional[Union[str, Path]], optional) – Where to look for the config file. Defaults to None.

Returns

_description_

Return type

Path

ntfy_wrapper.utils.load_conf(conf_path=None)

Loads a config file from the given path. Expects the INI format and will use configparser.

Parameters
  • conf_path (Optional[Union[str, Path]], optional) – Where to load the conf

  • None. (from. Defaults to) –

Returns

The configuration as a dictionary.

Return type

dict

ntfy_wrapper.utils.print
ntfy_wrapper.utils.write_conf(conf_path, conf)

Write the configuration file as an INI file. Always prepend the file with comments and example.

Parameters
  • conf_path (Path) – The path to the configuration file.

  • conf (Dict[str, Union[str, List[str]]]) – The configuration to write.

Return type

None