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

Add property 'extracts' with 'exsentences=2' #21

Closed
macloo opened this issue Apr 6, 2019 · 3 comments
Closed

Add property 'extracts' with 'exsentences=2' #21

macloo opened this issue Apr 6, 2019 · 3 comments
Assignees

Comments

@macloo
Copy link

macloo commented Apr 6, 2019

This is nicer than summary, imo, because you get to specify how many sentences you want. Jemisin has a really long summary, so you can test with with numbers greater than 2.

More readable in browser:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&exsentences=2&titles=N._K._Jemisin

JSON version:
https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exintro&explaintext&exsentences=2& format=json&titles=N._K._Jemisin

@martin-majlis
Copy link
Owner

Thanks for this suggestion.

My goal was to make the API very simple - so there is no possibility now how to tune parameters passed to underlying API calls.

But I believe that both approaches could be there - one simple and the other one which allows you te exactly specify which parameters.

Goal of this issue is to be able to pass parameters from - https://en.wikipedia.org/w/api.php?action=help&modules=query%2Bextracts

import sys
import wikipediaapi
wikipediaapi.log.setLevel(level=wikipediaapi.logging.DEBUG)

# Set handler if you use Python in interactive mode
out_hdlr = wikipediaapi.logging.StreamHandler(sys.stderr)
out_hdlr.setFormatter(wikipediaapi.logging.Formatter('%(asctime)s %(message)s'))
out_hdlr.setLevel(wikipediaapi.logging.DEBUG)
wikipediaapi.log.addHandler(out_hdlr)

wiki = wikipediaapi.Wikipedia('en')
page = wiki.page('N._K._Jemisin')
print(page.summary)

@martin-majlis
Copy link
Owner

It is possible to use this functionality in version 0.5.0

Example:

import wikipediaapi
wiki = wikipediaapi.Wikipedia('en')
page = wiki.page('Python_(programming_language)')
len(wiki.extracts(page, exsentences=1))
# 75
len(wiki.extracts(page, exsentences=2))
# 234

If you have any other suggestions, please, let me know.

@macloo
Copy link
Author

macloo commented Apr 7, 2019

Amazing! Thank you!

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

No branches or pull requests

2 participants