39 lines
908 B
Python
39 lines
908 B
Python
from pathlib import Path
|
|
import os
|
|
import yaml
|
|
|
|
CONFIG_PATH = "~/.config/smallprint/config.yml"
|
|
|
|
config = {
|
|
"OWM": "Your OpenWeatherMap token goes here",
|
|
"CITY": "City name",
|
|
"PRINTER_FILE": "/dev/usb/lp0",
|
|
"PRINTER_USB_ID": "",
|
|
"PRINTER_INTERFACE": 0,
|
|
"PRINTER_ENDPOINT": 0x01,
|
|
"WEBDAV_USER": "",
|
|
"WEBDAV_PASSWORD": "",
|
|
"WEBDAV_SERVER": "",
|
|
"CALENDAR_PATH": "",
|
|
}
|
|
|
|
|
|
def load_config():
|
|
global config
|
|
path = Path(CONFIG_PATH).expanduser() # Generate the path to the config file
|
|
|
|
if not path.parent.is_dir():
|
|
os.mkdir(path.parent)
|
|
|
|
if not path.is_file():
|
|
# Create sample file
|
|
with path.open("w") as cfg_file:
|
|
cfg_file.write(yaml.dump(config))
|
|
|
|
return False
|
|
|
|
else:
|
|
with path.open("r") as cfg_file:
|
|
config = yaml.load(cfg_file.read(), Loader=yaml.FullLoader)
|
|
|
|
return config
|