jenkins-bot has submitted this change and it was merged.
Change subject: Add an ItemPage.iterlinks function to yield sitelinks ......................................................................
Add an ItemPage.iterlinks function to yield sitelinks
Change-Id: I43ab820a5d97a22619dc5753d98bdd4ceec277f7 --- M pywikibot/page.py 1 file changed, 17 insertions(+), 0 deletions(-)
Approvals: Merlijn van Deen: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 72540eb..81daf92 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2540,6 +2540,23 @@ 'claims': self.claims }
+ def iterlinks(self, family=None): + """ + Iterates through all the sitelinks + @param family: string/Family object which represents what family of + links to iterate + @type family: str|pywikibot.family.Family + @return: iterator of pywikibot.Page objects + """ + if not hasattr(self, 'sitelinks'): + self.get() + if not isinstance(family, pywikibot.family.Family): + family = pywikibot.site.Family(family) + for dbname in self.sitelinks: + pg = Page(pywikibot.site.APISite.fromDBName(dbname), self.sitelinks[dbname]) + if not family or family == pg.site.family: + yield pg + def getSitelink(self, site, force=False): """ Returns the title (unicode string) for the specific site
pywikibot-commits@lists.wikimedia.org