Created
September 26, 2017 20:06
-
-
Save JacobHearst/c26875dfd19446dcfe88c8aff61c6d73 to your computer and use it in GitHub Desktop.
A simple rhyme finder built off of the api from datamuse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from urllib.request import urlopen | |
HEADERS = ["One", "Two", "Three", "Four or more", "======"] | |
BORDER = "======" | |
url = "https://api.datamuse.com/words?rel_rhy=" + \ | |
input("Input a word to find out what rhymes: ").split(' ')[0] | |
data = json.load(urlopen(url)) | |
syl_arrays = {} | |
for var in range(0, 4): | |
syl_arrays[var] = [datum['word'] | |
for datum in data if datum['numSyllables'] is var + 1] | |
for index, array in enumerate(syl_arrays): | |
if syl_arrays[index]: | |
print("%s %s Syllable Rhymes %s" % (BORDER, HEADERS[index], BORDER)) | |
for word in syl_arrays[index]: | |
stuff = 1 | |
print(word, end=' ', sep=' ', flush=True) | |
print('\n') | |
found = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment