Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tweepy
- import random
- def get_api():
- CONSUMER_KEY = os.environ['CONSUMER_KEY']
- CONSUMER_SECRET = os.environ['CONSUMER_SECRET']
- ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
- ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET']
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
- return tweepy.API(auth)
- def make_tweet(tweet):
- get_api().update_status(tweet)
- def get_from_file(filename):
- with open(filename) as file:
- words = file.readlines()
- words = [word.strip() for word in words]
- words = list(set(words))
- def get_topic():
- topics = get_from_file('topics')
- return random.choice(topics)
- def get_modifier():
- modifiers = get_from_file('modifiers')
- return random.choice(modifiers)
- def get_modifiers():
- n = random.randint(0,2)
- return [get_modifier() for _ in range(n)]
- def lambda_handler(event, context):
- topic = get_topic()
- modifiers = get_modifiers()
- modifiers.append(topic)
- tweet = ' '.join(modifiers)
- tweet = tweet.replace('- ', '-')
- make_tweet('dsa ' + tweet + ' caucus')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement