-
Notifications
You must be signed in to change notification settings - Fork 0
/
markov.py
51 lines (39 loc) · 1.48 KB
/
markov.py
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
import random
from os import listdir
from os.path import isfile, join
import markovify
# import pprint
def main():
files = [f for f in listdir('./pokemon') if isfile(join('./pokemon', f))]
with open('./corruptdex.txt', 'w') as outfile:
for fname in files:
with open('./pokemon/' + fname) as infile:
outfile.write(infile.read())
with open('./corruptdex.txt') as f:
text = f.read()
text_model = markovify.Text(text)
# text_model.get_value = get_value
pokemon_names = map(lambda p: p.split('.')[0].split('-')[1].capitalize(), files)
pokemon = random.choice(list(pokemon_names))
tweeted = False
failure = 0
while tweeted is False:
pokemon_tweet = text_model.make_sentence_with_start(pokemon)
if len(pokemon_tweet) < 140:
print(pokemon_tweet)
tweeted = True
it_tweet = text_model.make_sentence_with_start('It')
if len(it_tweet) < 140:
print(' ' + it_tweet)
its_tweet = text_model.make_sentence_with_start('Its')
if len(its_tweet) < 140:
print(' ' + its_tweet)
last_tweet = text_model.make_sentence_with_start('This')
if len(last_tweet) < 140:
print(' ' + last_tweet)
print(' ' + text_model.make_short_sentence(140))
else:
failure += 1
print("Failure number: " + str(failure))
if __name__ == "__main__":
main()