craftbeerpi4-pione/cbpi/utils/utils.py

21 lines
378 B
Python
Raw Normal View History

2019-01-05 20:43:48 +01:00
from cbpi.utils.encoder import ComplexEncoder
2018-11-16 20:35:59 +01:00
2019-01-02 21:20:44 +01:00
__all__ = ['load_config',"json_dumps"]
2018-11-04 00:47:26 +01:00
2018-11-01 19:50:04 +01:00
import json
2018-11-01 21:27:37 +01:00
import yaml
2018-11-01 19:50:04 +01:00
2018-11-01 21:27:37 +01:00
def load_config(fname):
2019-08-16 21:36:55 +02:00
2018-11-16 20:35:59 +01:00
try:
with open(fname, 'rt') as f:
2019-08-16 21:36:55 +02:00
data = yaml.load(f, Loader=yaml.FullLoader)
2018-11-16 20:35:59 +01:00
return data
2018-12-29 00:27:19 +01:00
except Exception as e:
2021-02-16 20:37:51 +01:00
2018-11-16 20:35:59 +01:00
pass
2018-11-01 21:27:37 +01:00
2018-11-01 19:50:04 +01:00
def json_dumps(obj):
2018-11-01 21:27:37 +01:00
return json.dumps(obj, cls=ComplexEncoder)