Refactor Code

main
Hammy 4 years ago
parent 3cd17f516c
commit d47a90b338

@ -1,19 +1,16 @@
from bot.winston import Winston def send_tweet(bot, tweet_text):
def send_tweet(tweet_text):
"""Sends a tweet to Twitter""" """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""" """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""" """Likes a tweet based on it's ID"""
Winston.bot.create_favorite(id=tweet_id) bot.create_favorite(id=tweet_id)

@ -1,6 +1,18 @@
import logging
import random
from bot.commands import send_tweet
from bot.winston import Winston from bot.winston import Winston
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def event_handler(event, context): def event_handler(event, context):
"""Sends random tweet from list of potential tweets""" """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}")

@ -1,26 +1,18 @@
import random
from twython import Twython from twython import Twython
from bot.aws_secrets import get_secret from bot.aws_secrets import get_secret
from bot.commands import send_tweet
class Winston: class Winston:
bot = Twython( def __init__(self):
get_secret("CONSUMER_KEY"), self.bot = Twython(
get_secret("CONSUMER_SECRET"), get_secret("CONSUMER_KEY"),
get_secret("ACCESS_TOKEN_KEY"), get_secret("CONSUMER_SECRET"),
get_secret("ACCESS_TOKEN_SECRET") get_secret("ACCESS_TOKEN_KEY"),
) get_secret("ACCESS_TOKEN_SECRET")
)
@staticmethod self.potential_tweets = [
def potential_tweets():
return [
"Hello! I'm Winston From Overwatch!", "Hello! I'm Winston From Overwatch!",
"Winston! From! Overwatch!", "Winston! From! Overwatch!",
"Winston? From Overwatch?" "Winston? From Overwatch?"
] ]
@staticmethod
def request_handler():
send_tweet(random.choice(Winston.potential_tweets()))

Loading…
Cancel
Save