Tools for Python scripts or terminal
Project description
invesytoolbox
A set of useful tools, created for my own convenience, but you might find it useful too.
Why "invesy"? Invesy (from German Inhaltsverwaltungssystem == content management system) is a closed source cms I created with Thomas Macher. It's only used in-house, that's why we didn't bother making it open source.
Invesy runs on Zope, so most of the individual website's logic runs in restricted Python. That's one reason for this toolbox: providing a set of useful functions in one single package which can be allowed in our restricted Python environment.
That's also why all date and time functions also take into account the old DateTime (as opposed to datetime) package, which is Zope is still relying upon heavily.
Lastly there are a few functions I need for Python scripts on my servers (which run FreeBSD, but they should run on any Unixoid system, possibly even Windows).
What's in the box?
- data_tools
- date_time_tools
- email_phone_tools
- locales_tools
- restricted_python_tools
- security_tools
- terminal_tools
- text_name_tools
data_tools
dict_from_dict_list
Create a dictionary from a list of dictionaries. You need to provide the key that's to be used.
create_vcard
Provide a dictionary, get a vCard.
dict_2unicode
- Converts all keys and values in a dictionary from bytes to unicode.
- All keys and values are changed from bytes to unicode, if applicable.
- Other data types are left unchaged, including other compound data types.
value_2datatype
Convert a value to a datatype
this function has two modes:
- it uses a json file with the metadata (types of variables by name)
- it makes educated guesses in converting a string (don't feed bytes to this function!)
dict_2datatypes
Converts all data of a dictionary to specific (json metadata) or guessed types using value_2datatype.
sort_dictlist
Sorts a list of dictionaries. A single or multiple keys can provided for sorting.
date_time_tools
get_dateformat
Guess the correct format string (like %d.%m.%Y
) to correctly convert a string to some date format (datetime.datetime, datetime.date or DateTime.DateTime).
str_to_dt
convert a string to datetime.datetime
str_to_DT
convert a string to DateTime.DateTime
str_to_date
convert a string to datetime.date
DT_to_dt
convert DateTime.DateTime to datetime.datetime
DT_to_date
convert DateTime.DateTime to datetime.date
date_to_dt
convert datetime.date to datetime.datetime
date_to_DT
convert datetime.date to DateTime.DateTime
convert_datetime
Using the convert-functions above, convert a date, time or string to any other type.
get_calendar_week
Get the calendar week from a date, time or string.
get_dow_number
Get the day of week number from a string or a date and time format.
get_isocalendar
Get the isocalendar tuple (year, week, dow nb) of a date, time or string.
get_monday (obsolete)
from year and week.
daterange_from_week
Get the first and last day of a week.
dates_from_week
Get all days of a week.
day_from_week
Get a specific day from a week.
monday_from_week
self explanatory
last_week_of_year
Get the last week of the year (sometimes 52, sometimes 53)
email_phone_tools
create_email_message
Create an email message (no sending)
process_phonenumber
- Processes a phonenumber and returns it in international format.
- Checks if a phonenumber is valid
locales_tools
get_locale
Get the current locale, returns a dictionary containing (with examples):
- locale (tuple): ('de_AT', 'utf-8')
- locale_string: 'de_AT'
- language: 'de'
- country: 'AT'
- currency: 'EUR'
fetch_all_countries
Returns a tuple, a list, a dictionary or a dictionary of dictionaries.
format_price
Formats a price according to the locale, ex: 4537 -> € 4.537,-
get_country
Returns all the data for a country as a dictionary.
get_language_name
Returns the name of a given language code in a language of choice.
fetch_holidays
Fetch the official holidays for a country in a specific period of time (given in years or a date range).
is_holiday
Check if a date is a holiday in a specific country (or in your current locale).
security_tools
create_secure_key
Generate a key (default 256 bit)
create_key
Create a key or password
check_password_security
Checks if a password (or any string) meets certain criteria
terminal_tools
print_
Enhanced print function, specially enhanced for printing in the terminal.
wait_for_key
Wait for a pressed key to continue.
text_name_tools
and_list
creates a human-readable list, including "and" (or any similar word, i.e. in another language), like
1, two, Three and 4
capitalize_text
Capitalize text or names. This is specially handy for names which otherwise would be capitalized wrongly with string's "title" method like:
- Conan McArthur
- Susanne Mayr-Grünwald
- Maria de Angelis
get_gender
of a prename.
leet
Create a leet from any string.
Georg --> 630r9
sort_names
Sorts by name, prename: splits only at the last space before sorting.
Correctly sorts names
- with special characters, like umlauts
- combined names
- names with prefixes (like de or von)
examples:
- Maria de Angelis
- Susanne Mayr-Grünwald
map_special_chars
Converts any string to ascii, sometimes converting a single character to two, like for German umlauts (only if sort == False):
ä --> ae
ö --> oe
ü --> ue
ß --> ss
sort_word_list
Sort a list of words using map_special_chars.
History
0.0.2 (2022-06-09)
- removed VERSION file
0.0.1 (2022-06-09)
- first version
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.