27 lines
645 B
Python
27 lines
645 B
Python
from typing import NamedTuple, List
|
|
|
|
import yaml
|
|
from asyncache import cached
|
|
from cachetools import FIFOCache
|
|
|
|
|
|
class LegendItem(NamedTuple):
|
|
color: str
|
|
description: str
|
|
link: str = None
|
|
|
|
|
|
# this will be cached permanently, i.e., the server process needs to be restarted to apply config changes
|
|
# note that caching doesn't work at all with iterators (for obvious reasons)
|
|
@cached(FIFOCache(1))
|
|
def read_legend_from_config_file() -> List[LegendItem]:
|
|
rv = []
|
|
|
|
with open("config.yml") as f:
|
|
data = yaml.safe_load(f)
|
|
|
|
for item in data.get("legend", []):
|
|
rv.append(LegendItem(**item))
|
|
|
|
return rv
|