Outsource twitter-code to plugin

This commit is contained in:
dadav
2019-10-03 21:09:34 +02:00
parent 26fe8ca059
commit 76bccec572
2 changed files with 53 additions and 25 deletions

View File

@ -104,31 +104,6 @@ if args.do_manual:
if Agent.is_connected():
plugins.on('internet_available', config, log)
if config['twitter']['enabled'] and log.is_new() and log.handshakes > 0:
import tweepy
logging.info("detected a new session and internet connectivity!")
picture = '/dev/shm/pwnagotchi.png'
display.update(force=True)
display.image().save(picture, 'png')
display.set('status', 'Tweeting...')
display.update(force=True)
try:
auth = tweepy.OAuthHandler(config['twitter']['consumer_key'], config['twitter']['consumer_secret'])
auth.set_access_token(config['twitter']['access_token_key'], config['twitter']['access_token_secret'])
api = tweepy.API(auth)
tweet = Voice(lang=config['main']['lang']).on_log_tweet(log)
api.update_with_media(filename=picture, status=tweet)
log.save_session_id()
logging.info("tweeted: %s" % tweet)
except Exception as e:
logging.exception("error while tweeting")
quit()
agent.start_ai()