bots are safely imported in the backend, except twitterDMs
This commit is contained in:
parent
55a804f0d6
commit
4343be7e06
15
active_bots/__init__.py
Normal file
15
active_bots/__init__.py
Normal file
|
@ -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)
|
||||||
|
|
|
@ -18,7 +18,11 @@ class MastodonBot(Bot):
|
||||||
:return: list of statuses
|
:return: list of statuses
|
||||||
"""
|
"""
|
||||||
mentions = []
|
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:
|
try:
|
||||||
notifications = m.notifications()
|
notifications = m.notifications()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -13,7 +13,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TwitterBot(Bot):
|
class TwitterBot(Bot):
|
||||||
def get_api(self, user):
|
def get_api(self, user):
|
||||||
keys = user.get_api_keys()
|
keys = user.get_twitter_credentials()
|
||||||
auth = tweepy.OAuthHandler(consumer_key=keys[0],
|
auth = tweepy.OAuthHandler(consumer_key=keys[0],
|
||||||
consumer_secret=keys[1])
|
consumer_secret=keys[1])
|
||||||
auth.set_access_token(keys[2], # access_token_key
|
auth.set_access_token(keys[2], # access_token_key
|
||||||
|
@ -27,7 +27,11 @@ class TwitterBot(Bot):
|
||||||
:return: reports: (list of report.Report objects)
|
:return: reports: (list of report.Report objects)
|
||||||
"""
|
"""
|
||||||
reports = []
|
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()
|
last_mention = user.get_seen_tweet()
|
||||||
try:
|
try:
|
||||||
if last_mention == 0:
|
if last_mention == 0:
|
||||||
|
|
|
@ -27,6 +27,8 @@ if __name__ == '__main__':
|
||||||
if isinstance(ActiveBot, type) and issubclass(ActiveBot, Bot):
|
if isinstance(ActiveBot, type) and issubclass(ActiveBot, Bot):
|
||||||
bots.append(ActiveBot())
|
bots.append(ActiveBot())
|
||||||
|
|
||||||
|
# Mailinglists not fully implemented yet. debug
|
||||||
|
bots.pop(1)
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
for user in db.active_users:
|
for user in db.active_users:
|
||||||
|
@ -39,5 +41,5 @@ if __name__ == '__main__':
|
||||||
bot2.post(user, status)
|
bot2.post(user, status)
|
||||||
time.sleep(60) # twitter rate limit >.<
|
time.sleep(60) # twitter rate limit >.<
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.error('Shutdown.', exc_info=True)
|
logger.error("Shutdown.", exc_info=True)
|
||||||
shutdown()
|
shutdown()
|
||||||
|
|
3
bot.py
3
bot.py
|
@ -1,7 +1,8 @@
|
||||||
class Bot(object):
|
class Bot(object):
|
||||||
# returns a list of Report objects
|
# returns a list of Report objects
|
||||||
def crawl(self, user):
|
def crawl(self, user):
|
||||||
pass
|
reports = []
|
||||||
|
return reports
|
||||||
|
|
||||||
# post/boost Report object
|
# post/boost Report object
|
||||||
def post(self, user, report):
|
def post(self, user, report):
|
||||||
|
|
2
user.py
2
user.py
|
@ -201,7 +201,7 @@ schlitz
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def get_twitter_token(self):
|
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, ))
|
(self.uid, ))
|
||||||
return db.cur.fetchall()
|
return db.cur.fetchall()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue