mirror of
https://github.com/thewesker/allanxaesthetic_ebooks.git
synced 2025-12-20 04:11:07 -05:00
19
ebooks.py
19
ebooks.py
@@ -1,8 +1,8 @@
|
|||||||
import random
|
import random
|
||||||
import markov
|
|
||||||
import twitter
|
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import twitter
|
||||||
|
import markov
|
||||||
from local_settings import *
|
from local_settings import *
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
@@ -17,6 +17,8 @@ def filter_tweet(tweet):
|
|||||||
tweet.text = re.sub(r'(\#|@|(h\/t)|(http))\S+','',tweet.text) #Take out URLs, hashtags, hts, etc.
|
tweet.text = re.sub(r'(\#|@|(h\/t)|(http))\S+','',tweet.text) #Take out URLs, hashtags, hts, etc.
|
||||||
tweet.text = re.sub(r'\n','', tweet.text) #take out new lines.
|
tweet.text = re.sub(r'\n','', tweet.text) #take out new lines.
|
||||||
tweet.text = re.sub(r'\"|\(|\)', '', tweet.text) #take out quotes.
|
tweet.text = re.sub(r'\"|\(|\)', '', tweet.text) #take out quotes.
|
||||||
|
tweet.text = re.sub(r'\xe9', 'e', tweet.text) #take out accented e
|
||||||
|
tweet.text = re.sub(r'\&', '&', tweet.text) #clean up escaped html ampersands
|
||||||
return tweet.text
|
return tweet.text
|
||||||
|
|
||||||
def grab_tweets(api, max_id=None):
|
def grab_tweets(api, max_id=None):
|
||||||
@@ -50,7 +52,12 @@ if __name__=="__main__":
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
mine = markov.MarkovChainer(order)
|
mine = markov.MarkovChainer(order)
|
||||||
for tweet in source_tweets:
|
for tweet in source_tweets:
|
||||||
|
if re.search('([\.\!\?\"\']$)', tweet):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
tweet+="."
|
||||||
mine.add_text(tweet)
|
mine.add_text(tweet)
|
||||||
|
|
||||||
for x in range(0,10):
|
for x in range(0,10):
|
||||||
ebook_tweet = mine.generate_sentence()
|
ebook_tweet = mine.generate_sentence()
|
||||||
|
|
||||||
@@ -61,13 +68,19 @@ if __name__=="__main__":
|
|||||||
print ebook_tweet
|
print ebook_tweet
|
||||||
|
|
||||||
#if a tweet is very short, this will randomly add a second sentence to it.
|
#if a tweet is very short, this will randomly add a second sentence to it.
|
||||||
if ebook_tweet != None and len(ebook_tweet) < 40 and random.randint(0,5) == 0:
|
if ebook_tweet != None and len(ebook_tweet) < 40:
|
||||||
|
rando = random.randint(0,7)
|
||||||
|
if rando == 0:
|
||||||
print "Short tweet. Adding another sentence randomly"
|
print "Short tweet. Adding another sentence randomly"
|
||||||
newer_tweet = mine.generate_sentence()
|
newer_tweet = mine.generate_sentence()
|
||||||
if newer_tweet != None:
|
if newer_tweet != None:
|
||||||
ebook_tweet += " " + mine.generate_sentence()
|
ebook_tweet += " " + mine.generate_sentence()
|
||||||
else:
|
else:
|
||||||
ebook_tweet = ebook_tweet
|
ebook_tweet = ebook_tweet
|
||||||
|
elif rando == 1:
|
||||||
|
#say something crazy/prophetic in all caps
|
||||||
|
print "ALL THE THINGS"
|
||||||
|
ebook_tweet = ebook_tweet.upper()
|
||||||
|
|
||||||
#throw out tweets that match anything from the source account.
|
#throw out tweets that match anything from the source account.
|
||||||
if ebook_tweet != None and len(ebook_tweet) < 110:
|
if ebook_tweet != None and len(ebook_tweet) < 110:
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ class MarkovChainer(object):
|
|||||||
except:
|
except:
|
||||||
nw = False
|
nw = False
|
||||||
new_res = res[0:-2]
|
new_res = res[0:-2]
|
||||||
|
if new_res[0].istitle() or new_res[0].isupper():
|
||||||
|
pass
|
||||||
|
else:
|
||||||
new_res[0] = new_res[0].capitalize()
|
new_res[0] = new_res[0].capitalize()
|
||||||
sentence = ""
|
sentence = ""
|
||||||
for word in new_res:
|
for word in new_res:
|
||||||
|
|||||||
Reference in New Issue
Block a user