XXN has uploaded a new change for review. https://gerrit.wikimedia.org/r/323785
Change subject: Ported tag_nowcommons.py from compat to core ...................................................................... Ported tag_nowcommons.py from compat to core Change-Id: I069c1fef10662395f51ea8da68c983fcc75b10af --- A scripts/tag_nowcommons.py 1 file changed, 148 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/85/323785/2 diff --git a/scripts/tag_nowcommons.py b/scripts/tag_nowcommons.py new file mode 100644 index 0000000..05fabff --- /dev/null +++ b/scripts/tag_nowcommons.py @@ -0,0 +1,148 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +Bot tag local files available at Commons with the NowCommons template. + +""" +# +# (C) Multichill, 2011 +# (C) xqt, 2013 +# Ported from compat to core by XXN, 2016. +# +# Distributed under the terms of the MIT license. +# + +#from __future__ import absolute_import, unicode_literals + +__version__ = '$Id: e9ddae2c4412b27b6e3b6c95a71afb4a833431b7 $' + +import sys +import pywikibot +from pywikibot import i18n, pagegenerators +import image +from scripts.imagecopy import nowCommonsTemplate + + +skips = { + '_default': [u'NowCommons'], + 'wikipedia': { + 'en': [u'NowCommons', + u'CommonsNow', + u'Nowcommons', + u'NowCommonsThis', + u'Nowcommons2', + u'NCT', + u'Nowcommonsthis', + u'Moved to commons', + u'Now Commons', + u'Now at commons', + u'Db-nowcommons', + u'WikimediaCommons', + u'Now commons', + u'Do not move to Commons', + u'KeepLocal', + u'Keeplocal', + u'NoCommons', + u'Nocommons', + u'NotMovedToCommons', + u'Nmtc', + u'Not moved to Commons', + u'Notmovedtocommons', + ], + 'fy': [u'NowCommons', + u'Nowcommons', + ], + 'ro': [u'NowCommons', + u'Now Commons', + u'AcumCommons', + u'FOP Romania', + ], + 'ru': [u'NowCommons', + u'Now Commons', + u'NoCommons', + u'FoP-Russia', + u'FoP-Ukraine', + ], + 'uk': [u'NowCommons', + u'Now Commons', + u'NoCommons', + u'NoFoP', + ], + }, +} + + +class NoEnoughData(pywikibot.Error): + """ Error class for when the user doesn't specified all the data needed """ + + +def tagNowCommons(page): + + imagepage = pywikibot.FilePage(page.site, page.title()) + site = page.site + language = site.code#site.language() + family = site.family.name + + if not imagepage.fileIsOnCommons(): + + if family in skips and language in skips[family]: + localskips = skips[family][language] + else: + localskips = skips['_default'] + + for template in imagepage.templates(): + if template in localskips: + pywikibot.output( + u'The file %s is already tagged with NowCommons' + % imagepage.title()) + return + + imagehash = imagepage.latest_file_info.sha1 + commons = pywikibot.Site(u'commons', u'commons')#getSite + duplicates = commons.getFilesFromAnHash(imagehash) + if duplicates: + duplicate = duplicates.pop() + pywikibot.output(u'Found duplicate image at %s' % duplicate) + comment = i18n.twtranslate(imagepage.site, + 'commons-file-now-available', + {'localfile': imagepage.title( + withNamespace=False), + 'commonsfile': duplicate}) + if site.lang in nowCommonsTemplate: + template = nowCommonsTemplate[site.lang] + else: + template = nowCommonsTemplate['_default'] + + newtext = template % (duplicate,) + '\n' + imagepage.get() + pywikibot.showDiff(imagepage.get(), newtext) + try: + imagepage.put(newtext, comment) + except pywikibot.LockedPage: + return + + +def main(args): + generator = None + # Load a lot of default generators + genFactory = pagegenerators.GeneratorFactory() + + for arg in pywikibot.handleArgs(): + genFactory.handleArg(arg) + + generator = genFactory.getCombinedGenerator() + if not generator: + raise NoEnoughData( + 'You have to specify the generator you want to use for the script!') + + pregenerator = pagegenerators.PreloadingGenerator(generator) + for page in pregenerator: + if page.exists() and page.namespace() == 6 and \ + not page.isRedirectPage(): + tagNowCommons(page) + + +if __name__ == "__main__": + try: + main(sys.argv[1:]) + finally: + pywikibot.stopme() -- To view, visit https://gerrit.wikimedia.org/r/323785 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I069c1fef10662395f51ea8da68c983fcc75b10af Gerrit-PatchSet: 2 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XXN <dan...@yahoo.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits