Mercurial > personal > weather-server
diff weather_server/locations.py @ 26:7def5611895b
Add support for an index page displaying all locations.
This seems as good a time as any to declare 0.1.0.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sun, 10 Nov 2019 23:46:51 -0500 |
parents | 20c8ec56e447 |
children | 9bc3687e1e5e |
line wrap: on
line diff
--- a/weather_server/locations.py Sun Nov 10 23:43:37 2019 -0500 +++ b/weather_server/locations.py Sun Nov 10 23:46:51 2019 -0500 @@ -20,9 +20,10 @@ class Location: - def __init__(self, root: pathlib.Path): + def __init__(self, root: pathlib.Path, key: str): parser = configparser.ConfigParser(interpolation=None) self.root = root + self.key = key config_file = root / CONFIG_FILE try: with open(config_file, 'r') as infile: @@ -81,6 +82,9 @@ locs, _ = self.info return locs[name] + def locations(self) -> t.Dict[str, Location]: + return self.info[0] + def _maybe_reload(self) -> None: new_mtime = self.root.stat().st_mtime_ns _, old_mtime = self.info @@ -89,7 +93,7 @@ locations = {} for child in self.root.iterdir(): try: - locations[child.name] = Location(child) + locations[child.name] = Location(child, child.name) except ConfigError: pass # It's OK. Skip this. self.info = locations, new_mtime