Commons:Example of a bulk download, edit and upload (SVG heraldic shields)

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Examples with unified shades of red, blue and gold

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.

Download with Imker

[edit]
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

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

Uploaded with Pywikibot

[edit]

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