feat: add account groups, scheduled payments and cash flow calendar
This commit is contained in:
1 parent
a7e0a0fe58
commit
86c6daf695
46 files changed
+2548
-290
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""Fetch public brand icons from the listed official websites; keep existing catalog."""
|
||||
import hashlib, io, json, re, urllib.request, urllib.parse
|
||||
from pathlib import Path
|
||||
from PIL import Image
|
||||
folder = Path(__file__).resolve().parent.parent / 'assets' / 'icons'
|
||||
catalog = json.loads((folder / 'sources.json').read_text(encoding='utf-8'))
|
||||
brands = [('汇丰香港', 'https://www.hsbc.com.hk'), ('恒生银行', 'https://www.hangseng.com'), ('中银香港', 'https://www.bochk.com/en'), ('渣打香港', 'https://www.sc.com/hk'), ('东亚银行', 'https://www.hkbea.com'), ('星展香港', 'https://www.dbs.com.hk'), ('花旗香港', 'https://www.citibank.com.hk'), ('币安 Binance', 'https://www.binance.com'), ('Gate', 'https://www.gate.com'), ('Bybit', 'https://www.bybit.com'), ('Bitget', 'https://www.bitget.com')]
|
||||
def get(url):
|
||||
return urllib.request.urlopen(urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'}), timeout=20).read()
|
||||
failed = []
|
||||
for name, site in brands:
|
||||
if any(v['name'] == name for v in catalog): continue
|
||||
urls = {'币安 Binance': ['https://bin.bnbstatic.com/static/images/common/favicon.ico', 'https://bin.bnbstatic.com/static/images/common/favicon.png'], '中银香港': ['https://www.bochk.com/dam/bochk/desktop/top/favicon.ico', 'https://www.bochk.com/favicon.ico']}.get(name, [])
|
||||
try:
|
||||
html = get(site).decode('utf-8', errors='replace')
|
||||
for tag in re.findall(r'<link\b[^>]*>', html, re.I):
|
||||
attrs = dict(re.findall(r'([\w-]+)=["\']([^"\']*)["\']', tag))
|
||||
if 'icon' in attrs.get('rel', '').lower() and attrs.get('href'): urls.append(urllib.parse.urljoin(site + '/', attrs['href']))
|
||||
except Exception: pass
|
||||
urls += [urllib.parse.urljoin(site + '/', '/favicon.ico'), urllib.parse.urljoin(site + '/', '/favicon.png')]
|
||||
for url in dict.fromkeys(urls):
|
||||
try:
|
||||
raw = get(url)
|
||||
im = Image.open(io.BytesIO(raw)).convert('RGBA')
|
||||
im.thumbnail((256,256))
|
||||
out = io.BytesIO(); im.save(out, 'PNG'); png = out.getvalue()
|
||||
file = str(len(catalog) + 1).zfill(2) + '.png'
|
||||
(folder / file).write_bytes(png)
|
||||
catalog.append({'name':name,'source':url,'file':file,'sha256':hashlib.sha256(raw).hexdigest()})
|
||||
print('Added:', name)
|
||||
break
|
||||
except Exception: continue
|
||||
else: failed.append(name)
|
||||
(folder / 'sources.json').write_text(json.dumps(catalog, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
||||
if failed: print('Unavailable:', ', '.join(failed)); raise SystemExit(1)
|
||||
Reference in new issue
Block a user