diff --git a/bot/commands.py b/bot/commands.py index d5d942d..682d6dc 100644 --- a/bot/commands.py +++ b/bot/commands.py @@ -1,19 +1,16 @@ -from bot.winston import Winston - - -def send_tweet(tweet_text): +def send_tweet(bot, tweet_text): """Sends a tweet to Twitter""" - Winston.bot.update_status(status=tweet_text) + bot.update_status(status=tweet_text) -def follow_someone(username): +def follow_someone(bot, username): """Follows someone based on given username""" - Winston.bot.create_friendship(username=username) + bot.create_friendship(username=username) -def like_tweet(tweet_id): +def like_tweet(bot, tweet_id): """Likes a tweet based on it's ID""" - Winston.bot.create_favorite(id=tweet_id) + bot.create_favorite(id=tweet_id) diff --git a/bot/handler.py b/bot/handler.py index 15af678..589a3fe 100644 --- a/bot/handler.py +++ b/bot/handler.py @@ -1,6 +1,18 @@ +import logging +import random + +from bot.commands import send_tweet from bot.winston import Winston +logger = logging.getLogger() +logger.setLevel(logging.INFO) + def event_handler(event, context): """Sends random tweet from list of potential tweets""" - Winston.request_handler() + winston = Winston() + + random_tweet = random.choice(winston.potential_tweets) + send_tweet(winston.bot, random_tweet) + + logger.info(f"Random Tweet Sent: {random_tweet}") diff --git a/bot/winston.py b/bot/winston.py index 774714e..7618902 100644 --- a/bot/winston.py +++ b/bot/winston.py @@ -1,26 +1,18 @@ -import random from twython import Twython from bot.aws_secrets import get_secret -from bot.commands import send_tweet class Winston: - bot = Twython( - get_secret("CONSUMER_KEY"), - get_secret("CONSUMER_SECRET"), - get_secret("ACCESS_TOKEN_KEY"), - get_secret("ACCESS_TOKEN_SECRET") - ) - - @staticmethod - def potential_tweets(): - return [ + def __init__(self): + self.bot = Twython( + get_secret("CONSUMER_KEY"), + get_secret("CONSUMER_SECRET"), + get_secret("ACCESS_TOKEN_KEY"), + get_secret("ACCESS_TOKEN_SECRET") + ) + self.potential_tweets = [ "Hello! I'm Winston From Overwatch!", "Winston! From! Overwatch!", "Winston? From Overwatch?" ] - - @staticmethod - def request_handler(): - send_tweet(random.choice(Winston.potential_tweets()))