utils Module¶
-
utils.
DAY_SHORTCUTS
= {'heute': 0, 'morgen': 1, 'übermorgen': 2} Parsable shortcuts to describe days relative to today as keys and the corresponding days-offset relative to today as values.
-
utils.
JSONDict
Dictionary containing response from or data to send to the API.
alias of Dict[str, Any]
-
utils.
SCDict
Dictionary for every cafeterias ID the corresponding
stwon.ServingCollection
.alias of Dict[int, ServingsCollection]
-
utils.
TIMEZONE
: pytz.tzinfo.BaseTzInfo = <DstTzInfo 'Europe/Berlin' LMT+0:53:00 STD> Timezone object for Europe/Berlin
- Type
TIMEZONE
pytz.BaseTzInfo
-
utils.
TimesLiteral
Literals allowed for the
time
attribute of the various stwon types.alias of Literal[morning, noon, evening]
-
utils.
WEEKDAYS_LONG
= {'dienstag': 1, 'donnerstag': 3, 'freitag': 4, 'mittwoch': 2, 'montag': 0, 'samstag': 5, 'sonntag': 6} Dictionary with long name identifiers weekdays as keys and the corresponding 0-based integers as values.
-
utils.
WEEKDAYS_SHORT
= {'di': 1, 'do': 3, 'fr': 4, 'mi': 2, 'mo': 0, 'sa': 5, 'so': 6} Dictionary with short name identifiers weekdays as keys and the corresponding 0-based integers as values.
-
utils.
date_range
(start_date, end_date) Date-Equivalent of
range()
.Note
end_date
will not be included.
-
utils.
next_weekday
(day) Gives the date of the next weekday specified by
day
. Will never be today.
-
utils.
parse_iso_time
(iso_time) Parses an ISO time (e.g.
11:30
) and returns adatetime.time
object localized asTIMEZONE
.
-
utils.
remove_prefix
(text, prefix) Backwards compatible wrapper for
str.removeprefix()
.
-
utils.
setlocale
(name) Wrapper to set locale. Use like:
with setlocale('de_DE.UTF-8'): return string.strptime('%B %Y')
-
utils.
shortcut2date
(shortcut) Given one of
DAY_SHORTCUTS
gives the correspondingdatetime.date
relative todatetime.date.today()
- Parameters
shortcut (
Literal
[‘heute’, ‘morgen’, ‘übermorgen’]) – The shortcut. Leading or trailing whitespaces and periods will be stripped. Case insensitive.- Raises
ValueError – For invalid input.
- Return type
-
utils.
str2bool
(str_input: Literal[True]) → Literal[True] -
utils.
str2bool
(str_input: Literal[False]) → Literal[False] Shortcut for converting
str(boolean_input)
back to a boolean.
-
utils.
weekday2date
(day) Given an (abbreviation of a) weekday in the german format, returns a
datetime.date
of the next date with the corresponding weekday. Will never be today, even if the weekday fits.- Parameters
day (
str
) – The weekday abbreviation. Leading or trailing whitespaces and periods will be stripped. Case insensitive.- Raises
ValueError – For invalid input.
- Return type