jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[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(-)

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()

To view, visit change 462734. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id429548672099389a2e2f3636c7f8c1ca567053b
Gerrit-Change-Number: 462734
Gerrit-PatchSet: 4
Gerrit-Owner: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)