shellbot.lists package¶
Submodules¶
Module contents¶
-
class
shellbot.lists.
List
(context=None, **kwargs)[source]¶ Bases:
object
Implements an immutable list
This allows easy integration of external reference data such as list of e-mail addresses, etc.
-
class
shellbot.lists.
ListFactory
(context=None)[source]¶ Bases:
object
Manages named lists
Example:
factory = ListFactory(context=my_context) factory.configure() ... my_list = factory.get_list('The Famous Four')
-
apply_to_list
(name, apply)[source]¶ Handles each item of a named list
Parameters: - name (str) – designates the list to use
- apply (callable) – the function that is applied to each item
This function calls the provided function for each item of a named list.
For example, you could write an alerting system like this:
def alert(person): number = get_phone_number(person) send_sms(important_message, number) factory.apply_to_list('SupportTeam', alert)
Lambda functions are welcome as well. For example, this can be useful for the straightforward addition of participants to a given bot:
factory.apply_to_list(name='SupportTeam', apply=lambda x: my_bot.add_participant(x))
-
build_list
(attributes)[source]¶ Builds one list
Example in YAML:
- name: The Famous Four as_command: true items: - alice@acme.com - bob@project.org - celine@secret.mil - dude@bangkok.travel
The
as_command
parameter is a boolean that indicates if the list can be used as a shell command. Whenas_command
is set to true, the named list appears in the list of shell commands. Members of the list are added to a channel when the name of the list is submitted to the shell.
-
configure
()[source]¶ Loads lists as defined in context
This function looks for the key
lists
and below in the context, and creates a dictionary of named lists.Example configuration in YAML format:
lists: - name: The Famous Four items: - alice@acme.com - bob@project.org - celine@secret.mil - dude@bangkok.travel - name: Support Team items: - service.desk@acme.com - supervisor@brother.mil
Note that list names are all put to lower case internally, for easy subsequent references. With the previous examples, you can retrieve the first list with The Famous Four or with the famous four. This is spacially convenient for lists used as commands, when invoked from a mobile device.
-
get_list
(name)[source]¶ Gets a named list
Parameters: name (str) – Name of the target list Returns: an iterator An empty list is returned when the name is unknown.
Example use case, where an alert is sent to members of a team:
for person in factory.get_list('SupportTeam'): number = get_phone_number(person) send_sms(important_message, number)
-