-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwitterbot.py
27 lines (20 loc) · 879 Bytes
/
twitterbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/python3
import os
import random
import logging
import tweepy
from twitter_secrets import Secrets
from src.generate_unconditional_samples import sample_model
logfilename = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'bot.log')
logging.basicConfig(level=logging.DEBUG, filename=logfilename, format='%(asctime)s %(name)s %(levelname)s:%(message)s')
logger = logging.getLogger(__name__)
logger.info(f'log file path: {logfilename}')
results = sample_model()
logger.info('Sampling model succeeds')
results = results.split('\n')[1:-1]
logger.info(f'Fetched {len(results)} samples')
results = [line for line in results if len(line) <= 140]
auth = tweepy.OAuthHandler(Secrets.CONSUMER_KEY, Secrets.CONSUMER_KEY_SECRET)
auth.set_access_token(Secrets.ACCESS_TOKEN, Secrets.ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
api.update_status(random.choice(results))