-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHaikuMaker.py
100 lines (92 loc) · 2.61 KB
/
HaikuMaker.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
__author__ = 'David'
from dictionary import worddict
from random import choice, randint
import sched
import time
import multiprocessing
repeat = 'YES'
wrdcombo = {
'noun':('verb', 'adj', 'pro', 'adv','art','ppro','prep'),
'verb':('noun', 'adj', 'pro', 'adv','art', 'ppro', 'prep'),
'adj':['noun','noun'],
'pro':('adv','verb'),
'adv':['verb','verb'],
'art':('noun', 'adj', 'adv'),
'ppro':('adj','noun','adv','verb'),
'prep':('adj', 'noun')}
def wtcheck(lwt):
if lwt == 0:
wt = choice(list(worddict))
return(wt)
else:
wt = choice(list(wrdcombo[lwt]))
return(wt)
def HLines():
cline1 = []
cline2 = []
cline3 = []
def lineOne():
lwt = 0
syllables = 0
while syllables < 5:
type = wtcheck(lwt)
lwt = type
wordsyl = choice(list(worddict[type]))
word = choice(list(worddict[type][wordsyl]))
syllables += wordsyl
cline1.append(word)
if syllables != 5:
del cline1[:]
lineOne()
def lineTwo():
lwt = 0
syllables = 0
while syllables < 7:
type = wtcheck(lwt)
lwt = type
wordsyl = choice(list(worddict[type]))
word = choice(list(worddict[type][wordsyl]))
syllables += wordsyl
cline2.append(word)
if syllables != 7:
del cline2[:]
lineTwo()
def lineThree():
lwt = 0
syllables = 0
while syllables < 5:
type = wtcheck(lwt)
lwt = type
wordsyl = choice(list(worddict[type]))
word = choice(list(worddict[type][wordsyl]))
syllables += wordsyl
cline3.append(word)
if syllables != 5:
del cline3[:]
lineThree()
lineOne()
lineTwo()
lineThree()
return {'line1':(' '.join(cline1)),'line2':(' '.join(cline2)),'line3':(' '.join(cline3))}
#print(len(' '.join(cline1))+len(' '.join(cline2))+len(' '.join(cline3)))
def hshtg():
tg = ['#']
a = choice(list(worddict['adj']))
s1 = choice(list(worddict['adj'][a]))
n = choice(list(worddict['noun']))
s2 = choice(list(worddict['noun'][n]))
tg.append(s1)
tg.append(s2)
htag = (''.join(tg))
return htag
def mkHaiku(min,max):
s = sched.scheduler(time.time, time.sleep)
t = randint(min, max)
s.enter(t, 1, HLines)
s.enter(t, 2, hshtg)
s.run()
def haikuTimer():
global repeat
while repeat == "YES":
mkHaiku()
repeat = input('Do you want to generate another Haiku (YES or NO)?')