from time import gmtime from os import getuid from pwd import getpwuid from pathlib import Path from urllib import request from urllib.error import HTTPError from ssl import CERT_NONE, create_default_context from human import byte2human path = Path(__file__).parent.resolve() / '.logos' def downloadfile(filename, url): context = create_default_context() context.check_hostname = False context.verify_mode = CERT_NONE try: response = request.urlopen(url, context=context) except HTTPError as e: print(f"[logo] {e}: {url}") return filename = Path(filename).expanduser() if not filename.is_absolute(): filename = path / filename print(f" [logo.downloadfile] downloading {url}") content = response.read() print(f" [logo.downloadfile] writing {byte2human(len(content))} to {filename!s}") filename.parent.mkdir(parents=True, exist_ok=True) filename.write_bytes(content) # these logos can be replaced by user in the .cache directory logos = { 'logo1.png' : 'https://2sn.org/Download/logo/monashlogo.png', 'logo2.png' : 'https://2sn.org/Download/logo/mocalogo.png', } for logo, url in logos.items(): if not (path / logo).exists(): downloadfile(logo, url) LOGO1 = dict( logo = path / 'logo1.png', size = (0., 0.04j), pos = (.99j, 0.07j), align = (1j, 0j), ) LOGO1 = dict( logo = path / 'logo1.png', size = (0., 0.04j), pos = (.99j, 0.93j), align = (1j, 1j), ) LOGO2 = dict( logo = path / 'logo2.png', size = (0., 0.05j), pos = (.99j, 0.01j), align = (1j, 0j), ) LOGO2 = dict( logo = path / 'logo2.png', size = (0., 0.05j), pos = (.99j, 0.99j), align = (1j, 1j), ) CC = dict( text = f"\u00A9 {getpwuid(getuid())[4]} ({gmtime().tm_year})", pos = (1j, 0.5j), align = (1j, 0.5j), size = 16, color = '#80808080', angle = 90, font = 'Roboto-Light.ttf', )