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

Adapt Category getAllMembers to use queryGen #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions wikitools/category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently in December 2008, byte order marks (U+FEFF) were added to files for "utf-8": 8708055.

# Copyright 2008-2013 Alex Zaddach ([email protected])

# This file is part of wikitools.
Expand Down Expand Up @@ -61,7 +61,7 @@ def getAllMembers(self, titleonly=False, reload=False, namespaces=False):
for member in self.__getMembersInternal(namespaces):
members.append(member)
if titleonly:
ret.append(member.title)
ret.append(member['title'])
if titleonly:
return ret
if namespaces is False:
Expand Down Expand Up @@ -91,7 +91,7 @@ def getAllMembersGen(self, titleonly=False, reload=False, namespaces=False):
if namespaces is False:
self.members.append(member)
if titleonly:
yield member.title
yield member['title']
else:
yield member

Expand All @@ -106,10 +106,7 @@ def __getMembersInternal(self, namespaces=False):
params['cmnamespace'] = '|'.join([str(ns) for ns in namespaces])
while True:
req = api.APIRequest(self.site, params)
data = req.query(False)
for item in data['query']['categorymembers']:
yield page.Page(self.site, item['title'], check=False, followRedir=False)
try:
params['cmcontinue'] = data['query-continue']['categorymembers']['cmcontinue']
except:
break
self.categories = []
for data in req.queryGen():
self.categories.extend(data['query']['categorymembers'])
return self.categories