Skip to content

Commit fd152e0

Browse files
committed
flexible category_members ns params, tag for release
1 parent 91cf282 commit fd152e0

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

pwiki/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__all__ = ['wgen', 'wiki']
1+
__all__ = ['gquery', 'mquery', 'wgen', 'wiki']

pwiki/wiki.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ def load_cookies(self, cookie_jar: Path = _DEFAULT_COOKIE_JAR) -> bool:
108108
self._refresh_rights()
109109
self.is_logged_in = True
110110

111+
log.debug("%s: successfully loaded cookies from '%s'", self, cookie_jar)
112+
111113
return True
112114

113115
def save_cookies(self, output_path: Path = _DEFAULT_COOKIE_JAR):
@@ -296,18 +298,18 @@ def categories_on_page(self, title: str) -> list[str]:
296298
log.info("%s: fetching categories on pages: %s", self, title)
297299
return self._xq_simple(MQuery.categories_on_page, title)
298300

299-
def category_members(self, title: str, ns: list[Union[NS, str]] = []) -> list[str]:
301+
def category_members(self, title: str, ns: Union[list[Union[NS, str]], NS, str] = []) -> list[str]:
300302
"""Fetches the elements in a category.
301303
302304
Args:
303305
title (str): The title of the category to fetch elements from. Must include `Category:` prefix.
304-
ns (list[Union[NS, str]], optional): Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].
306+
ns (Union[list[Union[NS, str]], NS, str], optional): Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].
305307
306308
Returns:
307309
list[str]: a `list` containing `title`'s category members.
308310
"""
309311
log.info("%s: fetching category members of '%s'", self, title)
310-
return flatten_generator(GQuery.category_members(self, title, ns, MAX))
312+
return flatten_generator(GQuery.category_members(self, title, ns if isinstance(ns, list) else [ns], MAX))
311313

312314
def category_size(self, title: str) -> int:
313315
"""Queries the wiki and gets the number of pages categorized in `title`.
@@ -452,7 +454,7 @@ def links_on_page(self, title: str, *ns: Union[NS, str]) -> list[str]:
452454
Returns:
453455
list[str]: The `list` of wiki links contained in the text of `title`
454456
"""
455-
log.info("%s: fetching wikilinks on %s", self, title)
457+
log.info("%s: fetching wikilinks on '%s'", self, title)
456458
return self._xq_simple(MQuery.links_on_page, title, *ns)
457459

458460
def list_duplicate_files(self) -> list[str]:
@@ -517,7 +519,7 @@ def page_text(self, title: str) -> str:
517519
Returns:
518520
str: The text of `title`. `None` if `title` does not exist.
519521
"""
520-
log.info("%s: fetching page text of %s", self, title)
522+
log.info("%s: fetching page text of '%s'", self, title)
521523
return self._xq_simple(MQuery.page_text, title)
522524

523525
def prefix_index(self, ns: Union[NS, str], prefix: str) -> list[str]:
@@ -641,7 +643,7 @@ def what_transcludes_here(self, title: str, *ns: Union[NS, str]) -> list[str]:
641643
Returns:
642644
list[str]: The list of pages that transclude `title`.
643645
"""
644-
log.info("%s: fetching transclusions of %s", self, title)
646+
log.info("%s: fetching transclusions of '%s'", self, title)
645647
return self._xq_simple(MQuery.what_transcludes_here, title, *ns)
646648

647649
def whoami(self) -> str:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pwiki",
8-
version="0.0.2",
8+
version="1.0.0",
99
author="Fastily",
1010
author_email="fastily@users.noreply.github.com",
1111
description="A Python library for effortlessly interacting with Wikipedia/MediaWiki",

test/test_wiki.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_categories_on_page(self):
4848
self.assertListEqual(["Category:Fastily Test"], self.wiki.categories_on_page("User:Fastily/Sandbox/Page/3"))
4949

5050
def test_category_members(self):
51-
self.assertCountEqual(["File:FastilyTest.png"], self.wiki.category_members("Category:Fastily Test2", [NS.FILE]))
51+
self.assertCountEqual(["File:FastilyTest.png"], self.wiki.category_members("Category:Fastily Test2", NS.FILE))
5252

5353
def test_category_size(self):
5454
self.assertEqual(2, self.wiki.category_size("Category:Fastily Test2"))

0 commit comments

Comments
 (0)