jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/446244 )
Change subject: [cleanup] Code cleanup
......................................................................
[cleanup] Code cleanup
- remove preleading "u" from strings
- use single quotes
- use str.format() instead of modula operator when the line is changed
- use "\n" instead of "\r\n"
detached from
https://gerrit.wikimedia.org/r/#/c/pywikibot/core/+/444437/
Change-Id: Ibd4df68d45303f8be9b498823b7a17d50460fcec
---
M scripts/imageharvest.py
1 file changed, 27 insertions(+), 28 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imageharvest.py b/scripts/imageharvest.py
index 104f898..6e2bd5f 100644
--- a/scripts/imageharvest.py
+++ b/scripts/imageharvest.py
@@ -17,7 +17,7 @@
-justshown Choose _only_ images shown on the page, not those linked
"""
#
-# (C) Pywikibot team, 2004-2017
+# (C) Pywikibot team, 2004-2018
#
# Distributed under the terms of the MIT license.
#
@@ -58,14 +58,14 @@
soup = BeautifulSoup(f.read())
if not shown:
- tagname = "a"
- elif shown == "just":
- tagname = "img"
+ tagname = 'a'
+ elif shown == 'just':
+ tagname = 'img'
else:
- tagname = ["a", "img"]
+ tagname = ['a', 'img']
for tag in soup.findAll(tagname):
- link = tag.get("src", tag.get("href", None))
+ link = tag.get('src', tag.get('href', None))
if link:
ext = os.path.splitext(link)[1].lower().strip('.')
if ext in fileformats:
@@ -79,27 +79,27 @@
image_url = ''
if url == '':
if image_url:
- url = pywikibot.input(u"What URL range should I check "
- u"(use $ for the part that is changeable)")
+ url = pywikibot.input('What URL range should I check '
+ '(use $ for the part that is changeable)')
else:
- url = pywikibot.input(u"From what URL should I get the images?")
+ url = pywikibot.input('From what URL should I get the images?')
if image_url:
minimum = 1
maximum = 99
answer = pywikibot.input(
- u"What is the first number to check (default: 1)")
+ 'What is the first number to check (default: 1)')
if answer:
minimum = int(answer)
answer = pywikibot.input(
- u"What is the last number to check (default: 99)")
+ 'What is the last number to check (default: 99)')
if answer:
maximum = int(answer)
if not desc:
basicdesc = pywikibot.input(
- u"What text should be added at the end of "
- u"the description of each image from this url?")
+ 'What text should be added at the end of '
+ 'the description of each image from this url?')
else:
basicdesc = desc
@@ -107,7 +107,7 @@
ilinks = []
i = minimum
while i <= maximum:
- ilinks += [url.replace("$", str(i))]
+ ilinks += [url.replace('$', str(i))]
i += 1
else:
ilinks = get_imagelinks(url)
@@ -115,20 +115,19 @@
for image in ilinks:
if pywikibot.input_yn('Include image %s?' % image, default=False,
automatic_quit=False):
- desc = pywikibot.input(u"Give the description of this image:")
+ desc = pywikibot.input('Give the description of this image:')
categories = []
while True:
- cat = pywikibot.input(u"Specify a category (or press enter to
"
- u"end adding categories)")
+ cat = pywikibot.input('Specify a category (or press enter to '
+ 'end adding categories)')
if not cat.strip():
break
- if ":" in cat:
- categories.append(u"[[%s]]" % cat)
+ if ':' in cat:
+ categories.append('[[{}]]'.format(cat))
else:
- categories.append(u"[[%s:%s]]"
+ categories.append('[[%s:%s]]'
% (mysite.namespace(14), cat))
- desc += "\r\n\r\n" + basicdesc + "\r\n\r\n" + \
- "\r\n".join(categories)
+ desc += '\n\n' + basicdesc + '\n\n' +
'\n'.join(categories)
UploadRobot(image, description=desc).run()
elif answer == 's':
break
@@ -138,19 +137,19 @@
"""Process command line arguments and invoke bot."""
global shown
global mysite
- url = u''
+ url = ''
image_url = False
shown = False
desc = []
for arg in pywikibot.handle_args():
- if arg == "-pattern":
+ if arg == '-pattern':
image_url = True
- elif arg == "-shown":
+ elif arg == '-shown':
shown = True
- elif arg == "-justshown":
- shown = "just"
- elif url == u'':
+ elif arg == '-justshown':
+ shown = 'just'
+ elif url == '':
url = arg
else:
desc += [arg]
--
To view, visit
https://gerrit.wikimedia.org/r/446244
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibd4df68d45303f8be9b498823b7a17d50460fcec
Gerrit-Change-Number: 446244
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot