<jupyter_start><jupyter_text>Setup your Twitter Account Keys<jupyter_code>consumer_key = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
consumer_secret = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
access_token = '<KEY>'
access_token_secret = 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)<jupyter_output><empty_output><jupyter_text>Find Today's Trending Topics  Filter topics for nouns<jupyter_code>#Poll Google trends to get hot noun trends with the newspaper package

def get_hot_nouns():
    pos_counts = defaultdict(Counter)
    
    nouns=[]
    hots = newspaper.hot() #Get today's trending topics
    hots = [' {0}'.format(elem) for elem in hots] #add a space to each one
    hots = ''.join(hots) #Join them into one big string
    
    doc = nlp(hots)
    
    doc = nlp(hots) #Create Spacy Doc
    
    for token in doc:
        pos_counts[token.pos][token.orth] += 1

    for pos_id, counts in sorted(pos_counts.items()):
        pos = doc.vocab.strings[pos_id]
        for orth_id, count in counts.most_common():
            #print(pos, count, doc.vocab.strings[orth_id])
            if pos == 'NOUN':
                nouns.append(doc.vocab.strings[orth_id])
                
    nouns = ['{0} '.format(elem) for elem in nouns] #add a space to each one
    nouns = ''.join(nouns) #Join them into one big string
    return(nouns)<jupyter_output><empty_output><jupyter_text>Create Hashtags for Twitter Post<jupyter_code>#Poll Google trends to get hot noun trends

def get_hot_nouns_hashtagged():
    pos_counts = defaultdict(Counter)
    
    nouns=[]
    hots = newspaper.hot() #Get today's trending topics
    hots = [' {0}'.format(elem) for elem in hots] #add a space to each one
    hots = ''.join(hots) #Join them into one big string
    
    doc = nlp(hots)
    
    doc = nlp(hots) #Create Spacy Doc
    
    for token in doc:
        pos_counts[token.pos][token.orth] += 1

    for pos_id, counts in sorted(pos_counts.items()):
        pos = doc.vocab.strings[pos_id]
        for orth_id, count in counts.most_common():
            #print(pos, count, doc.vocab.strings[orth_id])
            if pos == 'NOUN':
                nouns.append(doc.vocab.strings[orth_id])
                
    nouns = ['#{0} '.format(elem) for elem in nouns] #add a space to each one
    nouns = ''.join(nouns) #Join them into one big string
    return(nouns)
get_hot_nouns_hashtagged()<jupyter_output><empty_output><jupyter_text>Create Your Twitter Caption w/Frinkiac API<jupyter_code>def get_meme_caption():
    hot_nouns = get_hot_nouns()
    url_image = "https://frinkiac.com/api/search?q=" + hot_nouns
    r = requests.get(url_image) 
    json = r.json() 
        # Extract the episode number and timestamp from the API response 
        # and convert them both to strings. 
    ID, episode, timestamp = map(str, json[0].values()) 
    image_url = "https://frinkiac.com/meme/" + episode + "/" + timestamp 
         #Combine each line of subtitles into one string. 
    #caption = "\n".join([subtitle["Content"] for subtitle in json["Subtitles"]]) 

    url_caption = "http://frinkiac.com/api/caption?e=" + episode +"&t=" + timestamp
    r = requests.get(url_caption) 
    json = r.json() 
    ID, episode, timestamp = map(str, json["Frame"].values())  
    image_url = "https://frinkiac.com/meme/" + episode + "/" + timestamp 
        # Combine each line of subtitles into one string. 
    caption = " ".join([subtitle["Content"] for subtitle in json["Subtitles"]])
    j=0
    hot_nouns_hashtag = []
    hot_noun_hashtag = []
    for hot_noun in hot_nouns:
        hot_noun_hashtag = ("#" + hot_nouns[j])
        hot_nouns_hashtag.append(hot_noun_hashtag)
        j=j+1
    
    hot_nouns_hashtagged = get_hot_nouns_hashtagged()
    caption = "Simpsons Bot Says: " + caption + hot_nouns_hashtagged
    response = requests.get(image_url, stream=True)
    with open('img.png', 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
    del response
    return(caption)<jupyter_output><empty_output><jupyter_text>Send Tweet<jupyter_code>def send_tweet(): 
    caption = get_meme_caption() 
    api.update_with_media(filename='img.png', status=caption)
    print("Tweet sent!") # If an error occurs, print it out<jupyter_output><empty_output><jupyter_text>Schedule Tweets<jupyter_code>#schedule it
schedule.every().day.at("10:00").do(send_tweet)

while True:
    schedule.run_pending()<jupyter_output><empty_output><jupyter_text>Create Script for Automation<jupyter_code>#1. Convert to Script:
#jupyter nbconvert --to script SimpsonsBot.ipynb

#2.Create .sh rile:
####
#'#!/bin/bash;
#'python /Users/whs/Desktop/StartUp/SimpsonsBot.py;
####

#3. Now make the .sh excecutable: 
#chmod a+x (yourscriptname.sh)

#4. Trigger .sh file to run on startup :
# MacOS: System Preferences >> Users and Groups >> Login Items<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12055455093429777, 'fraction_numerical': 0.00341571227647177, 'mean_word_length': 3.5964912280701755, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 34, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '397343', 'license': 'MIT', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1759, 'n_words': 400, 'path': 'SimpsonsBot-Clean.ipynb', 'repo_name': 'whs2k/TopicalFrinkiacBot', 'size': '5022'}