diff --git a/active_bots/__init__.py b/active_bots/__init__.py new file mode 100644 index 0000000..eedb95f --- /dev/null +++ b/active_bots/__init__.py @@ -0,0 +1,15 @@ +__all__ = [] + +import pkgutil +import inspect + +for loader, name, is_pkg in pkgutil.walk_packages(__path__): + module = loader.find_module(name).load_module(name) + + for name, value in inspect.getmembers(module): + if name.startswith('__'): + continue + + globals()[name] = value + __all__.append(name) + diff --git a/active_bots/mastodonbot.py b/active_bots/mastodonbot.py index 07a2311..94fabe3 100755 --- a/active_bots/mastodonbot.py +++ b/active_bots/mastodonbot.py @@ -18,7 +18,11 @@ class MastodonBot(Bot): :return: list of statuses """ mentions = [] - m = Mastodon(*user.get_masto_credentials()) + try: + m = Mastodon(*user.get_masto_credentials()) + except TypeError: + logger.error("No Mastodon Credentials in database.", exc_info=True) + return mentions try: notifications = m.notifications() except Exception: diff --git a/active_bots/twitterbot.py b/active_bots/twitterbot.py index fdf6045..5e5d31a 100755 --- a/active_bots/twitterbot.py +++ b/active_bots/twitterbot.py @@ -13,7 +13,7 @@ logger = logging.getLogger(__name__) class TwitterBot(Bot): def get_api(self, user): - keys = user.get_api_keys() + keys = user.get_twitter_credentials() auth = tweepy.OAuthHandler(consumer_key=keys[0], consumer_secret=keys[1]) auth.set_access_token(keys[2], # access_token_key @@ -27,7 +27,11 @@ class TwitterBot(Bot): :return: reports: (list of report.Report objects) """ reports = [] - api = self.get_api(user) + try: + api = self.get_api(user) + except Exception: + logger.error("Error Authenticating Twitter", exc_info=True) + return reports last_mention = user.get_seen_tweet() try: if last_mention == 0: diff --git a/backend.py b/backend.py index b66fcfa..31ce58f 100755 --- a/backend.py +++ b/backend.py @@ -27,6 +27,8 @@ if __name__ == '__main__': if isinstance(ActiveBot, type) and issubclass(ActiveBot, Bot): bots.append(ActiveBot()) + # Mailinglists not fully implemented yet. debug + bots.pop(1) try: while True: for user in db.active_users: @@ -39,5 +41,5 @@ if __name__ == '__main__': bot2.post(user, status) time.sleep(60) # twitter rate limit >.< except Exception: - logger.error('Shutdown.', exc_info=True) + logger.error("Shutdown.", exc_info=True) shutdown() diff --git a/bot.py b/bot.py index b003ab8..c288140 100644 --- a/bot.py +++ b/bot.py @@ -1,7 +1,8 @@ class Bot(object): # returns a list of Report objects def crawl(self, user): - pass + reports = [] + return reports # post/boost Report object def post(self, user, report): diff --git a/user.py b/user.py index 9823c78..13a8105 100644 --- a/user.py +++ b/user.py @@ -201,7 +201,7 @@ schlitz db.commit() def get_twitter_token(self): - db.execute("SELECT access_token, access_token_secret FROM twitter_accouts WHERE user_id = ?;", + db.execute("SELECT client_id, client_secret FROM twitter_accounts WHERE user_id = ?;", (self.uid, )) return db.cur.fetchall()