jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462734 )
Change subject: [cleanup] cleanup scripts/data_ingestion.py ......................................................................
[cleanup] cleanup scripts/data_ingestion.py
- use str.format(...) instead of modulo for type specifier arguments. - use single quotes for string literals - remove preleading "u" from strings
Change-Id: Id429548672099389a2e2f3636c7f8c1ca567053b --- M scripts/data_ingestion.py 1 file changed, 18 insertions(+), 17 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/data_ingestion.py b/scripts/data_ingestion.py index 83cc324..e4ad76e 100755 --- a/scripts/data_ingestion.py +++ b/scripts/data_ingestion.py @@ -59,12 +59,12 @@ """ self.URL = URL self.metadata = metadata - self.metadata["_url"] = URL - self.metadata["_filename"] = filename = posixpath.split( + self.metadata['_url'] = URL + self.metadata['_filename'] = filename = posixpath.split( urlparse(URL)[2])[1] - self.metadata["_ext"] = ext = filename.split(".")[-1] + self.metadata['_ext'] = ext = filename.split('.')[-1] if ext == filename: - self.metadata["_ext"] = ext = None + self.metadata['_ext'] = ext = None self.contents = None
if not site: @@ -120,19 +120,19 @@ params = {} params.update(self.metadata) params.update(extraparams) - description = u'{{%s\n' % template + description = '{{%s\n' % template for key in sorted(params.keys()): value = params[key] - if not key.startswith("_"): - description = description + ( - u'|%s=%s' % (key, self._safeTemplateValue(value))) + "\n" - description = description + u'}}' + if not key.startswith('_'): + description += ('|{}={}\n'.format( + key, self._safeTemplateValue(value))) + description += '}}'
return description
def _safeTemplateValue(self, value): """Replace pipe (|) with {{!}}.""" - return value.replace("|", "{{!}}") + return value.replace('|', '{{!}}')
def CSVReader(fileobj, urlcolumn, site=None, *args, **kwargs): @@ -188,7 +188,8 @@ """Process each page.""" duplicates = photo.findDuplicateImages() if duplicates: - pywikibot.output(u"Skipping duplicate of %r" % duplicates) + pywikibot.output('Skipping duplicate of {!r}' + .format(duplicates)) return duplicates[0]
title = photo.getTitle(self.titlefmt) @@ -221,15 +222,15 @@ """ configuration = {} # Set a bunch of defaults - configuration['csvDialect'] = u'excel' + configuration['csvDialect'] = 'excel' configuration['csvDelimiter'] = ';' - configuration['csvEncoding'] = u'Windows-1252' # FIXME: Encoding hell + configuration['csvEncoding'] = 'Windows-1252' # FIXME: Encoding hell
templates = configurationPage.templatesWithParams() for (template, params) in templates: if template.title(with_ns=False) == 'Data ingestion': for param in params: - (field, sep, value) = param.partition(u'=') + (field, sep, value) = param.partition('=')
# Remove leading or trailing spaces field = field.strip() @@ -273,7 +274,7 @@ try: config_page.get() except pywikibot.NoPage: - pywikibot.error('%s does not exist' % config_page) + pywikibot.error('{} does not exist'.format(config_page)) continue
configuration = DataIngestionBot.parseConfigurationPage(config_page) @@ -282,7 +283,7 @@ try: f = codecs.open(filename, 'r', configuration['csvEncoding']) except (IOError, OSError) as e: - pywikibot.error('%s could not be opened: %s' % (filename, e)) + pywikibot.error('{} could not be opened: {}'.format(filename, e)) else: with f: files = CSVReader(f, urlcolumn='url', @@ -297,5 +298,5 @@ bot.run()
-if __name__ == "__main__": +if __name__ == '__main__': main()
pywikibot-commits@lists.wikimedia.org