Skip to content

Commit

Permalink
ADD: function scraps word with prononciation now
Browse files Browse the repository at this point in the history
  • Loading branch information
techcentaur committed Apr 30, 2018
1 parent 354d3d0 commit 3bf1620
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,40 @@
import argparse
from bs4 import BeautifulSoup

def rhythmic_words(word):
def rhythmic_words(word, num):
print("[*] Getting rhyming words ...\n")
print("[*] Format: (Word, Pronunciation) \n")

url = "http://www.b-rhymes.com/rhyme/word/"+word
raw = requests.get(url)

soup = BeautifulSoup(raw.text, "lxml")
rows = soup.find_all('tr')

wordlist = []

for row in rows:

cols = row.find_all('td')
cols = [x.text.strip() for x in cols]

if len(cols)!=0:
print(cols[1], end=' ')

print("\n")
wordlist.append(cols)

if num>=len(wordlist):
for w in wordlist:
if len(w)!=0:
print("( "+w[1]+", "+w[2]+" )")
else:
for i in range(0, num):
if len(wordlist[i])!=0:
print("( "+wordlist[i][1]+", "+wordlist[i][2]+" )")


parser = argparse.ArgumentParser()
parser.add_argument("-r", "--rhyme", help="get rhyming words", type=str)
parser.add_argument("-r", "--rhyme", help="get rhyming words", type=str, required=True)
parser.add_argument("-n", "--number", type=int, help="number of words should be returned", default=20)

args = parser.parse_args()

if len(args.rhyme)!=0:
rhythmic_words(args.rhyme)
rhythmic_words(args.rhyme, args.number)

0 comments on commit 3bf1620

Please sign in to comment.