Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added oxford definition generator #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AriaMoradi
Copy link

I think the part of the ankigen_bot.py that uses AnkiAutomatic should be changed in a way that it accepts some kind of difinition provider and then it can accept more providers later(I think I might add more definition engines later..)

@AriaMoradi
Copy link
Author

just realized using selenium is not necessary at all :|
so Im going to rewrite this using urllib and lxml

@damaru2
Copy link
Owner

damaru2 commented May 6, 2018

I tried your code with the word "dog" and it is not only retrieving the definitions but the definitions of idioms that involve the word "dog" (the idioms don't even appear). Only definitions should be returned.

There is an extra "example =" in line 43.

Also, the function format escapes the "\n" making your program print "\n" instead of eol.

Anyway I think the format should be orthogonal and homogeneous across providers so only one example should be given, and in the same format as the result of the other provider.

Regarding the possibility of choosing different providers, I guess I'll unify the commands /language, /swap and this new feature under a command /settings that provides an interface with telegram buttons that allows you to configure your account as you please. And in the code I'll create a factory that will receive a string or a Enum with the type of provider and will build it. I'm thinking something along the lines of the provider inheriting from a base class with the functions pref and a function to remove the pattern and then a non implemented function that would be retrieve_defs that uses whatever online (or offline?) service and returns a list of strings that hopefully will have the same format for every provider.

Of what providers are you thinking about?. I'd be specially interested in adding support for more languages.

@damaru2
Copy link
Owner

damaru2 commented May 6, 2018

Also, if the definition does not exist your program raises an exception instead of returning the empty list

    line 34, in retrieve_defs
	doc_html = request.urlopen(url).read()
	File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
	return opener.open(url, data, timeout)
	File "/usr/lib/python3.5/urllib/request.py", line 472, in open
	response = meth(req, response)
	File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
	'http', request, response, code, msg, hdrs)
	File "/usr/lib/python3.5/urllib/request.py", line 510, in error
	return self._call_chain(*args)
	File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
	result = func(*args)
	File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
	raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

@AriaMoradi
Copy link
Author

ok, I will fix these issues as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants