from time import gmtime from os import getuid, mkdir from pwd import getpwuid from pathlib import Path from urllib import request from human import byte2human path = Path(__file__).parent.resolve() / '.logos' def downloadfile(filename, url): response = request.urlopen(url) 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), ) LOGO2 = dict( logo = path / 'logo2.png', size = (0., 0.05j), pos = (.99j, 0.01j), align = (1j, 0j), ) 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', )