def act(self, force_act=False, action=None, skip_responses=False): """ returns: (action, response) tuple. response type depends on the action that was performed. """ if not force_act: config = ConfigurationAccessor.get_or_create() if config and (config.is_tweeting is not None) and (not safe_int(config.is_tweeting)): logging.debug("config.is_tweeting is False; hiding") return () result = [] responded = False if not skip_responses: try: direct, response = self.respond() if (direct or response): # a response to a direct message or mention was generated responded = True if direct: result.append(direct.AsDict()) if response: result.append(response.AsDict()) except Exception, e: logging.error(e)
def new_api(cls): config = ConfigurationAccessor.get_or_create() if config and config.twitter_oauth_enabled and config.twitter_access_token: logging.debug("creating OAuth API instance") api = cls._new_oauth_api(config.twitter_access_token) else: raise Exception("no OAuth token stored in config") if safe_int(config.twitter_read_only): logging.debug("creating read-only Twitter API") api = ReadOnlyTwitterApi(api) return api
def test_safe_int_is_none(self): self.assertEquals(0, numbers.safe_int(None))