API

class twitter_monitor.core.Executor(notifier, routines, key_value_store={})

Responsible to run routines. This class must receive an instance of twitter_monitor.core.Notifier class and an array of routines.

Parameters:
  • notifier – An instance of twitter_monitor.core.Notifier
  • routines – A list of twitter_monitor.core.Routine subclasses (not instances)
  • key_value_store – A dictionary like storage. It is used to store info about last executions (like last execution time). It is usual to use a simple key store like anydbm.
routines_instances()

Instantiate and return all routines instances.

run()

Execute all routines. It returns True if all routines are executed with success.

class twitter_monitor.core.ExecutorFactory(routines, twitter_keys, setup_default_logger=True)

Factory responsible to create an twitter_monitor.core.Executor instance.

Parameters:
  • routines – A list of twitter_monitor.core.Routine subclasses (not instances)
  • twitter_keys

    A dictionary with api twitter keys. It must have these keys (you can manage all of them on https://apps.twitter.com/).

    • consumer_key
    • consumer_secret
    • access_token_key
    • access_token_secret
  • setup_default_logger – If True (default) it’ll setup the root logger.
create_default()

Create a default Executor and setup a default logger.

class twitter_monitor.core.Notifier(api)

It sends a message to destinations (followers) with twitter API.

Parameters:api – An API instance (for now, we are using Tweepy)
send(message)

Send a message to all destinations

Parameters:message – A message to send to all followers. USE UNICODE
class twitter_monitor.core.Routine(notifier, key_value_store={})

Routine representation

Parameters:
  • notifier – An instance of twitter_monitor.core.Notifier
  • key_value_store – A dictionary like storage. It is used to store info about last executions (like last execution time). It is usual to use a simple key store like anydbm.
clear_last_execution()

Clear last execution time of this routine

interval_minutes = None

Interval (in minutes) to execute routine

last_execution

Returns a datetime object with last execution of routine

name = None

Routine full name. ALWAYS USE UNICODE

notify(message)

Send the message

run()

Run this routine

short_name = None

Routine short name (it’ll be used in the message). ALWAYS USE UNICODE

uid

Routine unique id (md5 format)