Commons:Example of a bulk download, edit and upload (SVG heraldic shields)
Jump to navigation
Jump to search
The images in SVG heraldic shields by Madboy74 used to have different shades of the same colors. In this process the colors were automatically unified.
Done on Ubuntu 18.04.
tilman@daisu3:~/Downloads/Imker_v16.09.13$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
The category name SVG heraldic shields by Madboy74; proposed for color adjustment
contains a semicolon, which has to be escaped with a backslash.
tilman@daisu3:~/Downloads/Imker_v16.09.13$ java -jar imker-cli.jar --category=SVG_heraldic_shields_by_Madboy74\;_proposed_for_color_adjustment --outfolder=/home/tilman/Downloads/coa
Imker
Wikimedia Commons batch download.
v16.09.13
Folder: /home/tilman/Downloads/coa
Download 432 files?
Press enter to continue. (Abort with CTRL+C)
(1/432): 0083 Vischnich.svg
... saved
(2/432): 0126 Sayn-Vos v. Sayn.svg
... saved
(3/432): 0151 Falkenstein.svg
... saved
(4/432): 0188
interruption and completion |
---|
Something is wrong with File:Coa Illustration Cross Couped.svg. (The code is manually optimized, while the other files have typical Inkscape code.) (134/432): Coa Illustration Cross Couped.svg
Exception in thread "main" java.lang.UnknownError: MW API error. Server response was: <?xml version="1.0"?><api servedby="mw1402"><error code="maxlag" info="Waiting for 10.64.0.219: 3.4843389987946 seconds lagged." host="10.64.0.219" lag="3.4843389987946" type="db" xml:space="preserve">See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.</error></api>
at wiki.Wiki.fetch(Unknown Source)
at wiki.Wiki.getImage(Unknown Source)
at wiki.Wiki.getImage(Unknown Source)
at app.ImkerBase$1.fetch(Unknown Source)
at app.App.attemptFetch(Unknown Source)
at app.ImkerBase.downloadLoop(Unknown Source)
at app.ImkerCLI.download(Unknown Source)
at app.ImkerCLI.main(Unknown Source)
Remove image from category and continue (by running the same command again). (133/431): Coa Illustration Cross Contour.svg
... exists locally
(134/431): Coa Illustration Cross Disjoined.svg
... saved
(431/431): Zsinór,.svg
... saved
Completed downloads!
Verify checksums ...
(1/431): 0083 Vischnich.svg
... is validated
(2/431): 0126 Sayn-Vos v. Sayn.svg
... is validated
(3/431): 0151 Falkenstein.svg
... is validated
(4/431): 0188 Pyrmont-Henri III, C. de Pyrmont.svg
|
Color replacement with a Python script
[edit](An overlooked shade of yellow was #fee79b
in File:Coa Slovakia Town Garamszentkereszt.svg and File:Coa Switzerland Town Knonaueramt.svg.)
import os
old_colors = {
'yellow': ['#ffd200', '#FCDD09', '#f9e098'],
'white': ['#ffffff', '#fff', '#f2f2f2', '#ececec'],
'blue': ['#0039a6', '#003287'],
'red': ['#dc281e', '#e60000'],
'green': ['#009a3d', '#078930'],
'black1': ['fill:#000000'],
'black2': ['fill="#000000"'],
'black3': ["fill='#000000'"]
}
new_colors = {
'yellow': '#f9d26d',
'white': '#f5f5f5',
'blue': '#10679a',
'red': '#c83232',
'green': '#1e9646',
'black1': 'fill:#222222',
'black2': 'fill="#222222"',
'black3': "fill='#222222'"
}
for filename in os.listdir(os.path.dirname(os.path.realpath(__file__))):
if filename.endswith(".svg"):
f = open(filename, 'r')
content = f.read()
f.close()
for name, oldhexcodes in old_colors.items():
newhexcode = new_colors[name];
for oldhexcode_raw in oldhexcodes:
for oldhexcode in [oldhexcode_raw.lower(), oldhexcode_raw.upper()]:
content = content.replace(oldhexcode, newhexcode)
f = open(filename, 'w')
f.write(content)
f.close()
user-config.py
:
family = 'commons'
mylang = 'commons'
usernames['commons']['commons'] = 'MyUserName'
upload.py
:
import os
import sys
reload(sys)
sys.setdefaultencoding('utf-8') # needed for names like 'Ágas pólya.svg'
import pywikibot
from pywikibot.specialbots import UploadRobot
def main(args):
for filename in os.listdir(os.path.dirname(os.path.realpath(__file__))):
if filename.endswith(".svg"):
print('################################################################', filename)
local_file_path = filename
bot = UploadRobot(
[local_file_path],
description='This text is a description in Pywikibot. It is not supposed to be seen anywhere, because the original description should be kept.',
useFilename=filename,
keepFilename=True, # True to skip checking destination filename
verifyDescription=False, # False to skip checking description (change to bot-mode)
targetSite=pywikibot.getSite('commons', 'commons'),
summary='adjust colors (uploaded with [[Pywikibot]], see [[Commons:Example of a bulk download, edit and upload (SVG heraldic shields)|here]] for details)',
always=True, # do not always ask, if the file should be overwritten
ignore_warning=True
)
bot.run()
if __name__ == "__main__":
try:
main(sys.argv[1:])
finally:
pywikibot.stopme()