diff options
author | makefu <github@syntax-fehler.de> | 2020-03-31 22:23:38 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2020-03-31 22:23:38 +0200 |
commit | e4942fdab9a43712d56b38dbdb8421d38d7743df (patch) | |
tree | f45314001e9e80bcf9ca1d6ec22126db0907e751 /ebknotify/common.py | |
parent | b9471e7b0576dfbb1157c639c4a34b243f9dd61e (diff) |
ebknotify: add feed
Diffstat (limited to 'ebknotify/common.py')
-rw-r--r-- | ebknotify/common.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ebknotify/common.py b/ebknotify/common.py index 0566c40..c277c26 100644 --- a/ebknotify/common.py +++ b/ebknotify/common.py @@ -1,8 +1,26 @@ +import yaml +import json +from os.path import expanduser,exists import logging +from sys import exit -def set_lol(lol,log): +from html import unescape # python 3.4+ + +log = logging.getLogger("ebk-common") + +def set_lol(lol:str ,log) -> None: numeric_level = getattr(logging,lol.upper(),None) if not isinstance(numeric_level,int): raise AttributeError('No such log level {}'.format(lol)) logging.basicConfig(level=numeric_level) log.setLevel(numeric_level) + +def load_config(path:str) -> dict: + configpath = expanduser(path) + if not exists(configpath): + log.error(f"{configpath} does not exist, bailing out") + exit(1) + return yaml.safe_load(open(configpath)) + +def html_unescape(data): + return unescape(data.decode()) |