geotribu_cli.utils.formatters module

Helpers to format text and variables.

geotribu_cli.utils.formatters.convert_octets(octets)

Convert a mount of octets in readable size.

Paramètres:

octets (int) – mount of octets to convert

Renvoie:

ko, Mo, etc.

Type renvoyé:

size in a human readable format

Example:

>>> convert_octets(1024)
1 ko
>>> from pathlib import Path
>>> convert_octets(Path(my_file.txt).stat().st_size)
geotribu_cli.utils.formatters.url_add_utm(in_url)

Adds utm_* query parameters to the item URL.

Paramètres:

in_url (str) – input content URL.

Type renvoyé:

str

Renvoie:

URL with utm_* query parameters to track openings from this package.

Example:

>>> print(url_add_utm("https://geotribu.fr/articles/test/"))
https://geotribu.fr/articles/test/?utm_source=geotribu_cli&utm_medium=GeotribuToolbelt&utm_campaign=geotribu_cli_0.16.0
geotribu_cli.utils.formatters.url_content_name(in_url)

Retrieve filename from a content URL.

Paramètres:

in_url (str) – input content URL.

Type renvoyé:

str

Renvoie:

filename at the end of URL.

Example:

>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/"))
https://github.com/geotribu/website/blob/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/", mode='raw'))
https://github.com/geotribu/website/raw/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/", mode='edit'))
https://github.com/geotribu/website/edit/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
geotribu_cli.utils.formatters.url_content_source(in_url, mode='blob')

Retrieve remote source file from a content URL.

Paramètres:
  • mode (Literal['blob', 'edit', 'raw']) – display mode for source. Defaults to « blob ».

  • in_url (str) – input content URL. Defaults to « « .

Type renvoyé:

str

Renvoie:

URLs with utm_* query parameters to track openings from this package.

Example:

>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/"))
https://github.com/geotribu/website/blob/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/", mode='raw'))
https://github.com/geotribu/website/raw/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
>>> print(url_content_source("https://geotribu.fr/articles/2023/2023-05-04_annonce-changement-url-site-geotribu/", mode='edit'))
https://github.com/geotribu/website/edit/master/content/articles/2023/2023-05-04_annonce-changement-url-site-geotribu.md
geotribu_cli.utils.formatters.url_rm_query(in_url, param_startswith='utm_')

Remove existing query parameters (default: utm_*) from input URL.

Paramètres:
  • in_url (str) – input URL to clean

  • param_startswith (str) – start pattern of param to remove. Defaults to “utm_”.

Type renvoyé:

str

Renvoie:

URL without query parameters

Example:

>>> print(url_rm_query("https://geotribu.fr/articles/test/?utm_source=geotribu_cli&utm_medium=GeotribuToolbelt&utm_campaign=geotribu_cli_0.16.0"))
https://geotribu.fr/articles/test/