-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkov_gen.py
More file actions
53 lines (42 loc) · 1.55 KB
/
markov_gen.py
File metadata and controls
53 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Imports markov_python module and makes an instance of the MarkovChain class
# Adds speech text file
from cc_markov import MarkovChain
mc = MarkovChain()
MarkovChain.add_file(mc, 'Trump_speech.txt')
# Generates text and alters output into 'sonnet' form
# Uses a while loop to generate 12 words for 14 lines
# Capitalises first letters. Indents last 2 lines, to make a 'couplet'
print 'A little Trump sonnet... ', '\n'
count = 0
sonnet = []
while count <15:
x = MarkovChain.generate_text(mc, max_length=12)
s = ''.join([i[0].upper() + i[1:] for i in (x[0].split())])
y = s + ' ' + ' '.join(x[1:])
if count == 13:
y = ' ' + y
sonnet.append(y)
elif count == 14:
y = ' ' + y + '...'
sonnet.append(y)
else:
sonnet.append(y)
count +=1
sonnet = '\n'.join(sonnet)
print sonnet
# Imports tweepy, assigns the specific authorisation keys to access the API
# Iterates through one 'sonnet' and tweets each line every 15 minutes
#import tweepy, time
#enter the corresponding information from your Twitter application:
#CONSUMER_KEY = '*************************'
#CONSUMER_SECRET = '**************************'
#ACCESS_KEY = '**********************************'
#ACCESS_SECRET = '*********************************'
#auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
#auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
#api = tweepy.API(auth)
tweet = sonnet.splitlines()
print "\n" + "Trump Tweet:" + "\n" + tweet[0]
#for line in tweet:
#api.update_status(line)
#time.sleep(900)#Tweet every 15 minutes