Created
May 18, 2019 12:12
-
-
Save halfak/49645725293a2d19103b9cfb4fd8a7b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def query_revisions_by_titles(titles, batch=50, **params): | |
titles_iter = iter(titles) | |
while True: | |
batch_titles = list(islice(titles_iter, 0, batch)) | |
if len(batch_titles) == 0: | |
break | |
else: | |
doc = session.get(action='query', prop='revisions', | |
titles=batch_titles, **params) | |
for page_doc in doc['query']['pages']: | |
page_meta = {k: v for k, v in page_doc.items() | |
if k != 'revisions'} | |
if 'revisions' in page_doc: | |
for revision_doc in page_doc['revisions']: | |
revision_doc['page'] = page_meta | |
yield revision_doc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment