# HG changeset patch # User Paul Fisher # Date 1573447611 18000 # Node ID 7def5611895b95e685119d6acf411aa56eefe3b1 # Parent a4147ecb18b39677e6ed2cf4ed1964e1016684b1 Add support for an index page displaying all locations. This seems as good a time as any to declare 0.1.0. diff -r a4147ecb18b3 -r 7def5611895b setup.py --- a/setup.py Sun Nov 10 23:43:37 2019 -0500 +++ b/setup.py Sun Nov 10 23:46:51 2019 -0500 @@ -2,7 +2,7 @@ setuptools.setup( name='weather-server', - version='0.0.8', + version='0.1.0', packages=setuptools.find_packages(), python_requires='>=3.7', install_requires=[ diff -r a4147ecb18b3 -r 7def5611895b weather_server/locations.py --- 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 diff -r a4147ecb18b3 -r 7def5611895b weather_server/server.py --- a/weather_server/server.py Sun Nov 10 23:43:37 2019 -0500 +++ b/weather_server/server.py Sun Nov 10 23:46:51 2019 -0500 @@ -22,7 +22,11 @@ @app.route('/') def home(): - return 'Weather server' + locations = tuple(locs.locations().values()) + return flask.render_template( + 'index.html', + locations=locations, + ) @app.route('/_submit', methods=['POST']) def submit(): diff -r a4147ecb18b3 -r 7def5611895b weather_server/static/style.css --- a/weather_server/static/style.css Sun Nov 10 23:43:37 2019 -0500 +++ b/weather_server/static/style.css Sun Nov 10 23:46:51 2019 -0500 @@ -5,6 +5,11 @@ width: 100%; font-family: Roboto, sans-serif; + background: var(--root-background); + color: var(--root-color); + + --root-background: #263238; + --root-color: white; --temp-background: #0d47a1; --temp-text: white; @@ -15,6 +20,9 @@ body { margin: 0; padding: 0; +} + +body.location { display: flex; flex-flow: column nowrap; width: 100%; @@ -28,8 +36,8 @@ font: inherit; flex: none; - background: #263238; - color: white; + background: var(--root-background); + color: var(--root-color); padding: 12px 24px; font-size: 24px; @@ -38,11 +46,15 @@ justify-content: center; } +h1 a { + color: inherit; +} + h1 span { display: block; } -p { +.location p { margin: 0; padding: 0; font: inherit; @@ -50,7 +62,7 @@ line-height: 1; } -.plain p { +.location.plain p { box-sizing: border-box; flex: 1; position: relative; @@ -60,33 +72,33 @@ padding: 24px; } -.plain p.important .key { +.location.plain p.important .key { display: block; opacity: 75%; font-size: 18px; } -.plain p.important .value { +.location.plain p.important .value { margin-top: 0; font-size: 150px; display: flex; flex-flow: row nowrap; } -.plain p.important .value .unit { +.location.plain p.important .value .unit { font-size: 33%; font-weight: bold; opacity: 66%; padding-top: 0.25em; } -.fancy p.important { +.location.fancy p.important { position: relative; flex: 1; height: 200px; } -.fancy p.important canvas { +.location.fancy p.important canvas { display: block; position: absolute; top: 0; @@ -97,7 +109,7 @@ height: 100%; } -.fancy p.important .key { +.location.fancy p.important .key { display: block; position: absolute; top: 24px; @@ -110,21 +122,21 @@ opacity: 75%; } -.fancy p.important .value { +.location.fancy p.important .value { display: none; } -#temp { +.location #temp { background: var(--temp-background); color: var(--temp-text); } -#dewpoint { +.location #dewpoint { background: var(--dewpoint-background); color: var(--dewpoint-text); } -#timestamp { +.location #timestamp { flex: none; background: #263238; color: white; @@ -136,6 +148,43 @@ justify-content: center; } -#timestamp > span { +.location #timestamp > span { display: block; } + +.home a { + color: inherit; +} + +.home ul, .home li { + list-style: none; + margin: 0; + padding: 0; +} + +.home li:nth-child(odd) { + background: var(--temp-background); + color: var(--temp-text); +} + +.home li:nth-child(even) { + background: var(--dewpoint-background); + color: var(--dewpoint-text); +} + +.home li a { + display: block; + justify-content: space-between; + padding: 15px 24px; + font-size: 18px; + display: flex; + flex-flow: row wrap; +} + +.home li a b { + display: block; +} + +.home li a span { + display: block; +} diff -r a4147ecb18b3 -r 7def5611895b weather_server/templates/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/weather_server/templates/index.html Sun Nov 10 23:46:51 2019 -0500 @@ -0,0 +1,33 @@ + + + + The Weather In Places + + + + +

Weather

+ + + diff -r a4147ecb18b3 -r 7def5611895b weather_server/templates/location.html --- a/weather_server/templates/location.html Sun Nov 10 23:43:37 2019 -0500 +++ b/weather_server/templates/location.html Sun Nov 10 23:46:51 2019 -0500 @@ -10,8 +10,8 @@ rel="shortcut icon" href="{{ url_for('static', filename='thermometer.png') }}"> - -

{{ location.name }} conditions

+ +

Weather: {{ location.name }}

{% if last_reading %}

Temperature