def load_scripts(self): """ Loads scripts to self.scripts """ script_classes = script_loader.load_scripts('scripts.twitter_related', settings.INSTALLED_TWITTER_RELATED_SCRIPTS) log("Loading twitter related scripts") for script in script_classes: listen_to = script.listen_to if isinstance(script.listen_to, list) else [script.listen_to] for event in listen_to: self.scripts.setdefault(event, []).append(script()) log("Loaded {0} for type {1}".format(script.__name__, event))
def load_scripts(self): """ Loads scripts to self.scripts """ script_classes = script_loader.load_scripts( 'scripts.twitter_related', settings.INSTALLED_TWITTER_RELATED_SCRIPTS) log("Loading twitter related scripts") for script in script_classes: listen_to = script.listen_to if isinstance( script.listen_to, list) else [script.listen_to] for event in listen_to: self.scripts.setdefault(event, []).append(script()) log("Loaded {0} for type {1}".format(script.__name__, event))
def run(): log("Standalone run") script_classes = load_scripts('scripts.standalone', INSTALLED_STANDALONE_SCRIPTS) scripts = [script() for script in script_classes] remaining_chunks = {} for script in scripts: remaining_chunks[script.__class__.__name__] = script.repeat_time while True: sleep(STAND_ALONE_REPEAT_TIME_CHUNKS) try: for script in scripts: remaining_chunks[script.__class__.__name__] -= 1 if remaining_chunks[script.__class__.__name__] == 0: remaining_chunks[script.__class__.__name__] = script.repeat_time script.on_called() except TwythonRateLimitError as e: log("Rate limit error, asks to retry after {0}".format(e.retry_after)) time.sleep(min(int(e.retry_after), 5*60*60)) except TwythonError as e: log("Twython error: {0}".format(e))