-
Notifications
You must be signed in to change notification settings - Fork 0
/
powGenerator.py
49 lines (40 loc) · 1.53 KB
/
powGenerator.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
from findSentence import sentenceGrab
from phoneticWords import findPhonetics
from phoneticIndex import findPhoneticIndex
from random import randint
from math import floor
import sys
def main():
library = sys.argv[1]
subject = sys.argv[2]
dictionary = "/usr/share/dict/words"
phonetics = findPhonetics(subject, dictionary)
if len(phonetics) == 0:
print("Could not find any phonetic words.")
return
nearPhoneticNum = floor((phonetics[0][1] + phonetics[len(phonetics)-1][1]) / 2)
phonetics = [i for i in phonetics if i[1] <= nearPhoneticNum]
sentences = []
tries = 10
index = 0
while len(sentences) == 0 and index <= tries:
if len(phonetics) == 0:
print("No more phonetic words. Ending")
return
index += 1
punWord = phonetics[randint(0, floor(len(phonetics)/2))][0]
print(punWord)
sentences = sentenceGrab(punWord, library, True)
if len(sentences) == 0:
phonetics = [i for i in phonetics if i[0] != punWord]
print("Could not find sentence... Trying again")
if index >= tries:
print("Reached maximum tries. Ending")
return
punSentence = sentences[randint(0, len(sentences) - 1)]
sentenceIndex = punSentence.find(punWord)
punIndex = findPhoneticIndex(subject, punWord)
punSentence = punSentence[0:sentenceIndex + punIndex] + subject + punSentence[sentenceIndex + punIndex + len(subject):len(punSentence)]
print(punSentence)
if __name__ == "__main__":
main()