bottilities
short
Utility functions for bots. Used in botskeleton (and all the bots that use it) and puckfetcher.
long
These are in the order defined in bottilities.py,
which in turn is basically defined by order of creation.
Not really organized nicely,
sorry.
Methods
ensure_dir(directory)
Create directory if it doesn’t exist.
expand(directory)
Expand ~ to $HOME,
and expand other environment variables to their values,
in the provided path.
Designed for UNIX-based platforms:
unclear what will happen on others.
generate_downloader(headers, args, max_per_hour=30)
Produce a callable downloader.
Provide headers for URL call,
and provide some args
(for the rate limiting
(see that later in the document)),
which will be used to identify this function in rate-limiting.
max_per_hour is optional:
use it to decide how many times per hour downloads can happen.
The default is 30 times per hour.
The returned downloader is called as follows:
downloader = generate_downloader({"foo": "bar"}, "an identifier string")
downloader(url=url, dest=dest)
where url is where to download FROM and dest is where to SAVE the file.
It will make the directory for the file if it does not exist.
A text progress bar is shown during download,
and while rate limit is blocking.
max_clamp(val, limit)
Return val if it is less than limit,
otherwise return limit.
parse_int_string(int_string)
Given a string like “1 23 4-8 32 1”, return a unique list of those integers in the string, and the integers in the ranges in the string. For this example, the output would be [1, 4, 5, 6, 7, 8, 23, 32]. Non-numbers ignored. Not necessarily sorted
rate_limited(max_per_hour, *args)
A decorator to rate-limit a function
(ensures that it runs no more than max_per_hour times per hour by sleeping sometimes).
Called like this:
@util.rate_limited(120, name)
def a_function(var1, var2="foo"):
sanitize(filename, platform=None)
Remove disallowed characters from potential filename. Provide platform to sanitize for that platform, otherwise current platform is found and used.
set_up_logging(log_filename="log", verbosity=0)
Set up a logger with reasonable settings. Return it for log calls.
random_line(file_path, encoding=FORCED_ENCODING)
At time of writing,
FORCED_ENCODING is “UTF-8”.
Refer to code for latest.
Return a line from the provided file at random.
Metadata
Release files for bottilities 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bottilities-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for bottilities-1.4.0-py3-none-any.whl |
Release files / bottilities-1.4.0-py3-none-any.whl
| Download URL | bottilities-1.4.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
67a90e917c761819b3694803216150b31fc46de4497581f0bfa9fc7a7a8720bb
|
|
BLAKE2b-256 checksum How to use checksums |
6525ec10d63fc234275606d8ea7bd162d333fb7cb8d7001c10575d23fb86b019
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Security for bottilities 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.