XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/190137
Change subject: [FEAT] Category: Get newest pages
......................................................................
[FEAT] Category: Get newest pages
This returns the pages which have been added to a category ordered by
the creation date from newest to oldest.
Change-Id: I9bb3f74bbe2e3319ed2dbcdefab414a3204c2c32
---
M pywikibot/page.py
1 file changed, 19 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/37/190137/1
diff --git a/pywikibot/page.py b/pywikibot/page.py
index c63af01..d52beb5 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2439,6 +2439,25 @@
"""
return self.site.categoryinfo(self)
+ def newest_pages(self, total=None):
+ """Return the pages ordered by the creation date."""
+ latest = pywikibot.Timestamp.max
+ if total is None:
+ total = 0
+ # site.categorymember is not usable as it returns pages
+ for member in pywikibot.data.api.QueryGenerator(
+ list='categorymembers', cmsort='timestamp', cmdir='newer',
+ cmtitle=self.title().encode(self.site.encoding())):
+ page = pywikibot.Page(self.site, member['title'])
+ assert(page.namespace().id == member['ns'])
+ if page.oldest_revision.timestamp > latest:
+ yield page
+ total -= 1
+ if total == 0:
+ break
+ latest =
min(pywikibot.Timestamp.fromISOformat(member['timestamp']),
+ latest)
+
# ### DEPRECATED METHODS ####
@deprecated("list(Category.subcategories(...))")
def subcategoriesList(self, recurse=False):
--
To view, visit https://gerrit.wikimedia.org/r/190137
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9bb3f74bbe2e3319ed2dbcdefab414a3204c2c32
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits