#!/usr/bin/env python
# -*- coding: utf-8 -*-

import datetime as dt
import logging
import time

import tweepy

from tweet_builder import *
from credentials import *


# Housekeeping: do not edit

logging.basicConfig(filename='tweet_test.log', level=logging.DEBUG)
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)

INTERVALS = [1, 1, 1, 5, 10]

# What the bot will tweet

def gen_tweet():
    """Generate a tweet from markovify."""
    return str(create_tweet(authors[pick_author()]))


def is_tweet_safe(tweet):
    """using Mark Twain text inevitably leads to tweets with offensive langueage"""
    vulgarities = ['nigger', 'fuck']
    for vulg in vulgarities:
        if vulg in tweet.lower():
            return False
        else:
            return True


def main_no_tweet():
    while True:
        t = gen_tweet()
        if is_tweet_safe(t):
            # api.update_status(t) # DON'T TWEET
            logging.info("On {0} -- Tweeted: {1}".format(dt.datetime.today(), t))
            time.sleep(random.choice(INTERVALS))
            print("Tweeting: {}".format(t))
            print('...\nAll done!')



if __name__ == '__main__':
    #main()
    main_no_tweet()
