2021-04-20 10:27:47 +00:00
|
|
|
import os
|
2021-04-20 13:23:50 +00:00
|
|
|
import re
|
2021-04-20 10:27:47 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
JSON_INDENT = 4
|
|
|
|
JSON_FILENAME = 'template.json'
|
2021-04-20 11:02:13 +00:00
|
|
|
README_FILENAME = 'README.md'
|
2021-04-20 10:27:47 +00:00
|
|
|
SCRIPT_DIR = os.path.dirname(__file__)
|
|
|
|
NOTE_TYPES_DIR = os.path.join(SCRIPT_DIR, os.pardir, 'templates')
|
2021-04-20 13:23:50 +00:00
|
|
|
FONTS_DIR = os.path.join(SCRIPT_DIR, os.pardir, 'fonts')
|
|
|
|
|
|
|
|
if not os.path.isdir(FONTS_DIR):
|
|
|
|
os.mkdir(FONTS_DIR)
|
2021-04-20 10:27:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def read_num(msg: str = "Input number: ", min_val: int = 0, max_val: int = None) -> int:
|
|
|
|
resp = int(input(msg))
|
|
|
|
if resp < min_val or (max_val and resp > max_val):
|
|
|
|
raise ValueError("Value out of range.")
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
def select(items: list[str]) -> Optional[str]:
|
|
|
|
if not items:
|
|
|
|
print("Nothing to show.")
|
|
|
|
return
|
|
|
|
for idx, model in enumerate(items):
|
|
|
|
print(f"{idx}: {model}")
|
|
|
|
idx = read_num("\nSelect model number: ", max_val=len(items) - 1)
|
|
|
|
return items[int(idx)]
|
2021-04-20 13:23:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_used_fonts(template_css: str):
|
|
|
|
return re.findall(r"url\([\"'](\w+\.[ot]tf)[\"']\)", template_css, re.IGNORECASE)
|