Closed arcolife closed 10 years ago
the DisambiguationError object does store a list of the suggested article titles:
try:
page = wikipedia.page("Recommendation")
except wikipedia.exceptions.DisambiguationError as e:
print e.options
# [u'norm (philosophy)', u'Recommender systems', u'European Union recommendation', u'W3C recommendation', u'letter of recommendation']
yeah well that could be one option. I was thinking:
try:
page = wikipedia.page("Recommendation")
print page.summary
except:
topics = wikipedia.search("Recommendation")
print "Recommendation may refer to: "
for i, topic in enumerate(topics):
print i, topic
choice = int(raw_input("Enter a choice: "))
assert choice in xrange(len(topics))
print wikipedia.summary(topics[choice])
this would help counter the error and give the user a chance to select an input at run-time instead.
Sample output
Recommendation may refer to:
0 Recommendation
1 Recommender system
2 World Wide Web Consortium
3 Life imprisonment in England and Wales
4 Web standards
5 Recommendation (European Union)
6 List of ITU-T V-Series Recommendations
7 Recommendation letter
8 Driver Steering Recommendation
9 Rec. 709
Enter a choice:
that's definitely something you can do in a program, but I don't think it's a good idea to add raw_input to the library itself. wikipedia.exceptions.DisambiguationError
gets the options
parameter straight from the data returned from the Mediawiki servers for the disambiguation page, so it's probably more accurate than just doing a search.
I was doing search because it gives more results than e.options. But then that's wikipedia's response.
Alright, so I think this would be better suited for example usages rather than the library.
Yeah, if you want to add an example in a pull feel free though! Also, I'm a little swamped with work right now, so the project could definitely use some help with the other open issues if you're interested.
:+1:
For example:
gives the following error and terminates the program:
Perhaps a better response, maybe in a JSON format, would help? without termination, and instead ask for further clarification?