Skip to content

Commit

Permalink
updated dictcc to parse suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Jonczyk committed May 25, 2018
1 parent e4b9910 commit d5eb59d
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions dictcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ def parse_single_tag(tag):

return str_tag


def parse_all(html):
def parse_response(html):
soup = BeautifulSoup(html, 'html.parser')
data = [tag for tag in soup.find_all('td', 'td7nl')]

Expand All @@ -41,15 +40,25 @@ def parse_all(html):

return res_from_to

def parse_suggestions(html):
soup = BeautifulSoup(html, 'html.parser')
data = [tag.a.text for tag in soup.find_all('td', 'td3nl') if tag.a]

return data

def main(args):
c = request(args.word, args.prim, args.sec)
data = parse_all(c)
data = parse_response(c)

for pair in data:
print("{0[0]}\t==\t{0[1]}".format(pair))

if not data:
print(' '.join(["No translation found for:", args.word]))
suggestions = parse_suggestions(c)
print('\nHere are suggestions given by dict.cc:')
for s in suggestions:
print(" - {}".format(s))

return 0

Expand All @@ -73,7 +82,7 @@ def main(args):
print("Secondary lang must be in : [" + ", ".join(all_dict) + "]")
exit(1)
if args.prim == args.sec:
print("Languages must be different. Given : \"{}\" \"{}\"".format(args.prim, args.sec))
print("Given languages must be different. Given : \"{}\" and \"{}\"".format(args.prim, args.sec))
exit(1)

main(args)

0 comments on commit d5eb59d

Please sign in to comment.