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.

Type

Dict[str, int]

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.

Type

Dict[str, str]

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.

Type

Dict[str, str]

utils.date_range(start_date, end_date)

Date-Equivalent of range().

Note

end_date will not be included.

Parameters
  • start_date (date) – The start date.

  • end_date (date) – The end date.

Return type

Iterator[date]

utils.next_weekday(day)

Gives the date of the next weekday specified by day. Will never be today.

Parameters

day (int) – 0-based Specification of the weekday.

Return type

date

utils.parse_iso_time(iso_time)

Parses an ISO time (e.g. 11:30) and returns a datetime.time object localized as TIMEZONE.

Parameters

iso_time (str) – The ISO date.

Return type

time

Returns

The localized date object.

utils.remove_prefix(text, prefix)

Backwards compatible wrapper for str.removeprefix().

Parameters
  • text (str) – The text to remove the prefix from.

  • prefix (str) – The prefix to remove.

Return type

str

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 corresponding datetime.date relative to datetime.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

date

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.

Parameters

str_input (Literal[‘True’, ‘False’]) – The input.

Return type

bool

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

date