def run(): try: with TweetDatabase() as db: # Connect to Twitter API. api = TwitterAPI() # Get data. img_data = get_data(db) # Tweet it. api.tweet_image(img_data) logger.info('Tweeted %s', img_data) # Add record of tweet to database db.add(img_data) # Follow new followers api.follow_new() except Exception: logger.exception('Something went wrong.')