jenkins-bot has submitted this change and it was merged.
Change subject: Make obsolete site object can be created
......................................................................
Make obsolete site object can be created
Per discussion, this patch makes it possible to create an obsolete
site object while the site object will be prevented from writing.
In other words, it will be a read-only site. Consequently, this
patch solves bug 55146. Note that although obsolete
sites now become readable, they will not be in site.languages().
In addition, this patch makes pagelanglinks() return only non-obsolete
sites by default to make old scripts still functional, but it adds a
parameter to suppress this functionality.
Bug: 61120
Bug: 55146
Change-Id: I3d6ef66c369da7f0b64b821d7d78454192601839
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 39 insertions(+), 15 deletions(-)
Approvals:
Mpaa: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index b75bbc3..5c292f3 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -991,31 +991,40 @@
# ignore any links with invalid contents
continue
- def langlinks(self):
+ def langlinks(self, include_obsolete=False):
"""Return a list of all interlanguage Links on this page.
+
+ @param include_obsolete: if true, return even Link objects whose site
+ is obsolete
"""
# Data might have been preloaded
if not hasattr(self, '_langlinks'):
- self._langlinks = list(self.iterlanglinks())
+ self._langlinks = list(self.iterlanglinks(include_obsolete=True))
- return self._langlinks
+ if include_obsolete:
+ return self._langlinks
+ else:
+ return filter(lambda i: not i.site.obsolete, self._langlinks)
- def iterlanglinks(self, step=None, total=None):
+ def iterlanglinks(self, step=None, total=None, include_obsolete=False):
"""Iterate all interlanguage links on this page.
@param step: limit each API call to this number of pages
@param total: iterate no more than this number of pages in total
+ @param include_obsolete: if true, yield even Link object whose site
+ is obsolete
@return: a generator that yields Link objects.
"""
if hasattr(self, '_langlinks'):
- return iter(self._langlinks)
+ return iter(self.langlinks(include_obsolete=include_obsolete))
# XXX We might want to fill _langlinks when the Site
# method is called. If we do this, we'll have to think
# about what will happen if the generator is not completely
# iterated upon.
- return self.site.pagelanglinks(self, step=step, total=total)
+ return self.site.pagelanglinks(self, step=step, total=total,
+ include_obsolete=include_obsolete)
def data_item(self):
"""
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 3d85c6b..381d392 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -129,15 +129,15 @@
else:
self.__family = fam
+ self.obsolete = False
# if we got an outdated language code, use the new one instead.
if self.__code in self.__family.obsolete:
if self.__family.obsolete[self.__code] is not None:
self.__code = self.__family.obsolete[self.__code]
else:
# no such language anymore
- raise NoSuchSite("Language %s in family %s is obsolete"
- % (self.__code, self.__family.name))
- if self.__code not in self.languages():
+ self.obsolete = True
+ elif self.__code not in self.languages():
if self.__family.name in list(self.__family.langs.keys()) and \
len(self.__family.langs) == 1:
oldcode = self.__code
@@ -707,10 +707,15 @@
@param right: the rights the logged in user should have
not supported yet and thus ignored.
@returns: a decorator to make sure the requirement is statisfied when
- the decorated function is called.
+ the decorated function is called. The function can be called
+ with as_group='sysop' to override the group set in the
+ decorator.
"""
def decorator(fn):
def callee(self, *args, **kwargs):
+ if self.obsolete:
+ raise NoSuchSite("Language %s in family %s is obsolete"
+ % (self.code, self.family.name))
grp = kwargs.pop('as_group', group)
if grp == 'user':
self.login(False)
@@ -1959,8 +1964,14 @@
# No such function in the API (this method isn't called anywhere)
raise NotImplementedError
- def pagelanglinks(self, page, step=None, total=None):
- """Iterate all interlanguage links on page, yielding Link objects."""
+ def pagelanglinks(self, page, step=None, total=None,
+ include_obsolete=False):
+ """Iterate all interlanguage links on page, yielding Link objects.
+
+ @param include_obsolete: if true, yield even Link objects whose
+ site is obsolete
+
+ """
lltitle = page.title(withSection=False)
llquery = self._generator(api.PropertyGenerator,
type_arg="langlinks",
@@ -1974,9 +1985,13 @@
if 'langlinks' not in pageitem:
continue
for linkdata in pageitem['langlinks']:
- yield pywikibot.Link.langlinkUnsafe(linkdata['lang'],
- linkdata['*'],
- source=self)
+ link = pywikibot.Link.langlinkUnsafe(linkdata['lang'],
+ linkdata['*'],
+ source=self)
+ if link.site.obsolete and not include_obsolete:
+ continue
+ else:
+ yield link
def page_extlinks(self, page, step=None, total=None):
"""Iterate all external links on page, yielding URL strings."""
--
To view, visit https://gerrit.wikimedia.org/r/112842
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3d6ef66c369da7f0b64b821d7d78454192601839
Gerrit-PatchSet: 11
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: Pyfisch <pyfisch(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Revert "i18n doctest was missing an import"
......................................................................
Revert "i18n doctest was missing an import"
This reverts commit 45c4c4eb93ea6f60450d3dfe7cc0dcec9b08dcbe.
I do not see the sense of the previous commit.
fyflake does sometimes report nonsense. To test the method you
have to import the module(s) (which is trivial) but in the right
form:
>>> import pwb # if pywikibot is not a side package
>>> import pywikibot
>>> from pywikibot import i18n
(and if really necessary, place it obove the comment line)
Change-Id: Ie3c765f1520c6585f8e22f72c942ca7da0ebae75
---
M pywikibot/i18n.py
1 file changed, 0 insertions(+), 1 deletion(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 2e50bda..56fb9da 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -409,7 +409,6 @@
},
}
#use a number
- >>> import i18n
>>> i18n.twntranslate('en', 'test-changing', 0) % {'num': 'no'}
Bot: Changing no pages.
#use a string
--
To view, visit https://gerrit.wikimedia.org/r/117649
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3c765f1520c6585f8e22f72c942ca7da0ebae75
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: New bot to create new items. (now with pep8)
......................................................................
New bot to create new items.
(now with pep8)
Change-Id: I43a46ceaa09532a1215a9e5a4cd59d0d58b41683
---
A scripts/newitem.py
1 file changed, 113 insertions(+), 0 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/newitem.py b/scripts/newitem.py
new file mode 100644
index 0000000..3c28927
--- /dev/null
+++ b/scripts/newitem.py
@@ -0,0 +1,113 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+This script creates new items on Wikidata based on certain criteria.
+* When was the (Wikipedia) page created?
+* When was the last edit on the page?
+* Does the page contain interwiki's?
+
+"""
+#
+# (C) Multichill, 2014
+# (C) Pywikibot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+import json
+import pywikibot
+from pywikibot import pagegenerators
+from datetime import datetime
+from datetime import timedelta
+
+
+class NewItemRobot:
+ """
+ A bot to create new items
+ """
+ def __init__(self, generator, pageAge, lastEdit):
+ """
+ Arguments:
+ * generator - A generator that yields Page objects.
+ * pageAge - The minimum number of days that has passed since the page was created
+ * lastEdit - The minimum number of days that has passed since the page was last edited
+
+ """
+ self.generator = pagegenerators.PreloadingGenerator(generator)
+ self.repo = pywikibot.Site().data_repository()
+ self.pageAge = pageAge
+ self.pageAgeBefore = self.repo.getcurrenttime() - timedelta(days=self.pageAge)
+ self.lastEdit = lastEdit
+ self.lastEditBefore = self.repo.getcurrenttime() - timedelta(days=self.lastEdit)
+
+ def run(self):
+ """
+ Starts the robot.
+ """
+ pywikibot.output('Page age is set to %s days so only pages created before %s will be considered.' % (self.pageAge, self.pageAgeBefore.isoformat()))
+ pywikibot.output('Last edit is set to %s days so only pages last edited before %s will be considered.' % (self.lastEdit, self.lastEditBefore.isoformat()))
+
+ for page in self.generator:
+ pywikibot.output('Processing %s' % page)
+ item = pywikibot.ItemPage.fromPage(page)
+ if item.exists():
+ pywikibot.output('%s already has an item: %s. Doing a null edit on the page.' % (page, item))
+ page.put(page.get())
+ elif page.isRedirectPage():
+ pywikibot.output('%s is a redirect page. Skipping.' % page)
+ elif page.editTime() > self.lastEditBefore:
+ pywikibot.output('Last edit on %s was on %s. Too recent. Skipping.' % (page, page.editTime().isoformat()))
+ else:
+ (revId, revTimestamp, revUser, revComment) = page.getVersionHistory(reverseOrder=True, total=1)[0]
+ if revTimestamp > self.pageAgeBefore:
+ pywikibot.output('Page creation of %s on %s is too recent. Skipping.' % (page, page.editTime().isoformat()))
+ elif page.langlinks():
+ # FIXME: Implement this
+ pywikibot.output('Found language links (interwiki links). Haven\'t implemented that yet so skipping.')
+ else:
+ # FIXME: i18n
+ summary = u'Bot: New item with sitelink from %s' % (page.title(asLink=True, insite=self.repo), )
+
+ data = {'sitelinks':
+ {item.getdbName(page.site):
+ {'site': item.getdbName(page.site),
+ 'title': page.title()}
+ },
+ 'labels':
+ {page.site.lang:
+ {'language': page.site.lang,
+ 'value': page.title()}
+ }
+ }
+ pywikibot.output(summary)
+ item.editEntity(data, summary=summary)
+ # And do a null edit to force update
+ page.put(page.get())
+
+
+def main():
+ pageAge = 21
+ lastEdit = 7
+
+ gen = pagegenerators.GeneratorFactory()
+
+ for arg in pywikibot.handleArgs():
+ if arg.startswith('-pageage:'):
+ pageAge = int(arg[9:])
+ elif arg.startswith('-lastedit:'):
+ lastEdit = int(arg[10:])
+ if gen.handleArg(arg):
+ continue
+
+ generator = gen.getCombinedGenerator()
+ if not generator:
+ # FIXME: Should throw some help
+ return
+
+ bot = NewItemRobot(generator, pageAge, lastEdit)
+ bot.run()
+
+if __name__ == "__main__":
+ main()
--
To view, visit https://gerrit.wikimedia.org/r/116284
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I43a46ceaa09532a1215a9e5a4cd59d0d58b41683
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Addshore <addshorewiki(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: i18n doctest was missing an import
......................................................................
i18n doctest was missing an import
The doctest examples were missing an import to let one run the tests.
Detected by flake8: F821 undefined name 'i18n'
Change-Id: I5a3811be35cc52b0897384749bdffd33a40bbfc2
---
M pywikibot/i18n.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/i18n.py b/pywikibot/i18n.py
index 56fb9da..2e50bda 100644
--- a/pywikibot/i18n.py
+++ b/pywikibot/i18n.py
@@ -409,6 +409,7 @@
},
}
#use a number
+ >>> import i18n
>>> i18n.twntranslate('en', 'test-changing', 0) % {'num': 'no'}
Bot: Changing no pages.
#use a string
--
To view, visit https://gerrit.wikimedia.org/r/116295
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5a3811be35cc52b0897384749bdffd33a40bbfc2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>