treacle module¶
Treacle can also be used by other Python programs in order to provide similar after-hours functionality.
treacle.Treacle class¶
- class treacle.Treacle(config, config_as_dict=False)¶
Class for calculating office hours in multiple offices.
Parameters: - config (file or dict) – Configuration source to use. This uses syntax defined in Configuring treacle.
- config_as_dict (boot) – Treat the parameter config as a dict rather than a file, if True. This is useful when passing in configuration from a non-file source, such as for unit testing.
- in_hours(office=None, when=None)¶
Finds if it is business hours in the given office.
Parameters: - office (str or None) – Office ID to look up, or None to check if any office is in business hours.
- when (datetime.datetime) – When to check the office is open, or None for now.
Returns: True if it is business hours, False otherwise.
Return type: bool
Raises KeyError: If the office is unknown.
treacle.Office class¶
- class treacle.Office(config, section)¶
Represents an office configuration for Treacle.
This class should only be instantiated by Treacle, not by user applications.
Parameters: - config (configparser.ConfigParser) – Configuration object to use.
- section (str) – Name of the section to read this office’s configuration from.
- in_hours(when)¶
Find if the given datetime is in business hours for this office.
Parameters: when (datetime.datetime) – The time to check Returns: True if the given time is in business hours for the office, False otherwise. Return type: bool