Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions paperpi.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ type = "basic_clock"
# storage_days = 30

# met_no: The weather for the next 12 hours from met.no: temperature, rain and wind.
# Layouts (values for "layout"): hours_12, small, steps_3h, now, portrait_hours, portrait_now
# Layouts (values for "layout"): hours_12, three_rows, three_columns, now_and_today, six_hours,
# steps_3h, now, small, portrait_hours, portrait_now
[[plugin]]
id = "met_no-3a91d2f4"
name = "Weather Berlin"
Expand All @@ -120,6 +121,9 @@ place = "Berlin"
# temperature = "C"
# Rain in millimetres or inches. One of: "mm", "inch"
# rain = "mm"
# Wind speed, shown by the now layout (wind barbs are always in knots). One of: "m/s", "km/h",
# "mph", "knots"
# wind = "m/s"
# --- Settings every plugin has (all of them are in the first block) ---
# Seconds between updates (at least 5). Leave it out to use the plugin's suggestion (shown below)
# refresh = 1800
Expand All @@ -130,7 +134,8 @@ place = "Berlin"
# layout = "hours_12"

# met_no: The weather for the next 12 hours from met.no: temperature, rain and wind.
# Layouts (values for "layout"): hours_12, small, steps_3h, now, portrait_hours, portrait_now
# Layouts (values for "layout"): hours_12, three_rows, three_columns, now_and_today, six_hours,
# steps_3h, now, small, portrait_hours, portrait_now
[[plugin]]
id = "met_no-b7e40c19"
name = "Weather Rio"
Expand All @@ -150,6 +155,9 @@ place = "Rio"
# temperature = "C"
# Rain in millimetres or inches. One of: "mm", "inch"
# rain = "mm"
# Wind speed, shown by the now layout (wind barbs are always in knots). One of: "m/s", "km/h",
# "mph", "knots"
# wind = "m/s"
# --- Settings every plugin has (all of them are in the first block) ---
# Seconds between updates (at least 5). Leave it out to use the plugin's suggestion (shown below)
# refresh = 1800
Expand Down
Binary file added src/paperpi/fonts/Economica-Bold.ttf
Binary file not shown.
94 changes: 94 additions & 0 deletions src/paperpi/fonts/Economica-OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Copyright (c) 2012, Vicente Lamonaca (produccion.taller@gmail.com www.tipografia-montevideo.info www.tipotype.com),
with Reserved Font Name Economica.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
8 changes: 6 additions & 2 deletions src/paperpi/fonts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{"name": "title", "type": "text", "font": fonts.LATO_BOLD}

Without a ``font``, epdlib uses its own DejaVu Sans. Licences: ``Anton-OFL.txt``,
``Dosis-OFL.txt``, ``Lato-OFL.txt``, ``LibreCaslonText-OFL.txt``, ``Montserrat-OFL.txt``,
``Oswald-OFL.txt``.
``Dosis-OFL.txt``, ``Economica-OFL.txt``, ``Lato-OFL.txt``, ``LibreCaslonText-OFL.txt``,
``Montserrat-OFL.txt``, ``Oswald-OFL.txt``.
"""

from pathlib import Path
Expand All @@ -22,6 +22,10 @@
#: Font License 1.1, from Google Fonts: the static SemiBold file that PaperPi v1 shipped.
DOSIS_SEMIBOLD = str(FOLDER / "Dosis-SemiBold.ttf")

#: Economica Bold by Vicente Lamonaca, under the SIL Open Font License 1.1, from Google
#: Fonts: the static Bold file that PaperPi v1 shipped. Narrow, so large numbers fit.
ECONOMICA_BOLD = str(FOLDER / "Economica-Bold.ttf")

#: Lato Bold and Lato Italic by Łukasz Dziedzic, under the SIL Open Font License 1.1, from
#: Google Fonts (github.com/google/fonts, folder ofl/lato).
LATO_BOLD = str(FOLDER / "Lato-Bold.ttf")
Expand Down
37 changes: 24 additions & 13 deletions src/paperpi/plugins/met_no/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,28 @@ Feathers add up: a long and a short feather is 15 knots; a triangle and two long

## Layouts

| Layout | Shows |
| -------------------- | ----------------------------------------------------------------------------------- |
| `hours_12` (default) | the summary, an icon every 2 hours, then per hour the rain, temperature and wind |
| `steps_3h` | the summary, then 4 steps of 3 hours: icon, lowest and highest temperature, rain, wind |
| `now` | the current hour, large: icon, temperature and wind barb, with the summary below |
| `small` | for tiny screens (2" to 3"): a big icon, the temperature now, max, min and rain |
| `portrait_hours` | for upright screens: the summary, then one row per hour |
| `portrait_now` | for upright screens: a large icon for the current hour, then the summary |

| `hours_12` | `steps_3h` | `now` |
| Layout | Shows |
| -------------------- | ------------------------------------------------------------------------------------------ |
| `hours_12` (default) | the summary, an icon every 2 hours, then per hour the rain, temperature and wind |
| `three_rows` | now, +3 and +6 hours as rows: time, icon, temperature, rain and wind |
| `three_columns` | now, +3 and +6 hours as columns: time, icon, a large temperature and rain |
| `now_and_today` | the icon and temperature now; the highest and lowest temperature, and when the rain starts |
| `six_hours` | every 2 hours: hour, icon, temperature, and a bar with the rain of both hours |
| `steps_3h` | 4 steps of 3 hours: icon, highest temperature and rain |
| `now` | the current hour only, large: icon, temperature, and the wind as an arrow with its speed |
| `small` | for tiny screens (2" to 3"): a big icon, the temperature now, max, min and rain |
| `portrait_hours` | for upright screens: the summary, then one row per hour |
| `portrait_now` | for upright screens: a large icon for the current hour, then the summary |

All layouts from `three_rows` to `now` are made to be read from across the room: few items and large, bold text.

| `three_rows` | `three_columns` | `now_and_today` |
|---|---|---|
| ![hours_12](../../../../tests/images/met_no-hours_12-berlin-9in7.png) | ![steps_3h](../../../../tests/images/met_no-steps_3h-berlin-9in7.png) | ![now](../../../../tests/images/met_no-now-berlin-9in7.png) |
| ![three_rows](../../../../tests/images/met_no-three_rows-berlin-9in7.png) | ![three_columns](../../../../tests/images/met_no-three_columns-berlin-9in7.png) | ![now_and_today](../../../../tests/images/met_no-now_and_today-berlin-9in7.png) |

| `six_hours` | `steps_3h` | `now` |
|---|---|---|
| ![six_hours](../../../../tests/images/met_no-six_hours-berlin-9in7.png) | ![steps_3h](../../../../tests/images/met_no-steps_3h-berlin-9in7.png) | ![now](../../../../tests/images/met_no-now-berlin-9in7.png) |

| `small`, 2.13" | `portrait_hours`, upright | `portrait_now`, upright | `hours_12`, °F and inches, 7.5" |
|---|---|---|---|
Expand All @@ -78,8 +88,9 @@ Note: a saved forecast older than 6 hours is not used. Then the plugin's card on
| `place` | `""` | name shown at the top, e.g. `"Berlin"`; without it, the coordinates are shown |
| `temperature` | `"C"` | `"C"` (Celsius) or `"F"` (Fahrenheit) |
| `rain` | `"mm"` | `"mm"` or `"inch"` |
| `wind` | `"m/s"` | `"m/s"`, `"km/h"`, `"mph"` or `"knots"`: the wind speed in the `now` layout |

Wind is always in knots, because the barbs are drawn in knots.
Wind barbs are always in knots, whatever `wind` is set to.

The plugin asks for a new picture every 30 minutes unless you change `refresh`. met.no updates its forecasts about once an hour.

Expand All @@ -99,7 +110,7 @@ layout = "steps_3h" # optional; without it: hours_12

## Credits

The weather data is from [MET Norway](https://www.met.no/en), under the [Creative Commons 4.0 BY International](https://creativecommons.org/licenses/by/4.0/) license. The screen shows "Data: MET Norway", as the license asks. The weather icons are met.no's own, from [github.com/metno/weathericons](https://github.com/metno/weathericons), under the MIT license ([`icons/LICENSE`](icons/LICENSE)).
The weather data is from [MET Norway](https://www.met.no/en), under the [Creative Commons 4.0 BY International](https://creativecommons.org/licenses/by/4.0/) license. The screen shows "Data: MET Norway", as the license asks. The weather icons are met.no's own, from [github.com/metno/weathericons](https://github.com/metno/weathericons), under the MIT license ([`icons/LICENSE`](icons/LICENSE)). The large text uses Economica Bold by Vicente Lamonaca, under the SIL Open Font License 1.1 ([`fonts/Economica-OFL.txt`](../../fonts/Economica-OFL.txt)).

## For developers

Expand Down
95 changes: 87 additions & 8 deletions src/paperpi/plugins/met_no/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ...plugin import Context, Plugin, PluginSettings, ready, setting
from . import barbs, forecast
from .forecast import Forecast, Hour
from .layouts import HOURS, LAYOUTS
from .layouts import HOURS, LAYOUTS, PICKS

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -81,6 +81,11 @@ class Settings(PluginSettings):
rain: Literal["mm", "inch"] = setting(
"mm", group="Units", description="Rain in millimetres or inches"
)
wind: Literal["m/s", "km/h", "mph", "knots"] = setting(
"m/s",
group="Units",
description="Wind speed, shown by the now layout (wind barbs are always in knots)",
)


@dataclass(frozen=True)
Expand Down Expand Up @@ -200,6 +205,49 @@ def rain_summary_text(s: forecast.Summary, settings: Settings, zone) -> str:
return f"Rain {total} {rain_unit(settings)}, {spells_text(s.spells, zone)}"


#: Wind speed units: the number to multiply m/s by, and the text shown after the speed.
WIND_UNITS = {
"m/s": (1.0, "m/s"),
"km/h": (3.6, "km/h"),
"mph": (2.236936, "mph"),
"knots": (forecast.KNOTS, "kn"),
}


def wind_text(speed: float, unit: str) -> str:
""" "4 m/s": a wind speed in m/s, in the chosen unit."""
factor, name = WIND_UNITS[unit]
return f"{round(speed * factor)} {name}"


def wind_arrow(wind_from: float):
"""A plain, thick arrow that points where the wind is going: easier to see from a
distance than a barb. Drawn larger than shown, like the rain bars."""
size = 400
picture = Image.new("L", (size, size), 255)
draw = ImageDraw.Draw(picture)
middle = size / 2
draw.line((middle, 60, middle, size - 110), fill=0, width=36)
draw.polygon(
[(middle - 90, size - 150), (middle + 90, size - 150), (middle, size - 20)], fill=0
)
# Drawn pointing down: wind from the north (0°) goes south. Turned clockwise from there.
return picture.rotate(-wind_from, resample=Image.Resampling.BICUBIC, fillcolor=255)


def rain_amount(mm: float, settings: Settings) -> str:
""" "3.4 mm", or "dry" when it doesn't rain."""
number = rain_text(mm, settings.rain)
return f"{number} {rain_unit(settings)}" if number else "dry"


def rain_start_text(s: forecast.Summary, zone) -> str:
""" "Rain from 13:00", or "No rain"."""
if not s.spells:
return "No rain"
return f"Rain from {s.spells[0][0].astimezone(zone):%H}:00"


def summary_text(s: forecast.Summary, settings: Settings, zone) -> str:
return f"{temperatures_text(s, settings)} · {rain_summary_text(s, settings, zone)}"

Expand Down Expand Up @@ -270,7 +318,36 @@ def wind(hour: Hour):
"now_temp": lambda: f"{degrees(hours[0].temperature, t)}{t}",
"now_icon": lambda: icon(hours[0].symbol),
"now_barb": lambda: wind(hours[0]),
"now_degrees": lambda: degrees(hours[0].temperature, t),
"now_arrow": lambda: wind_arrow(hours[0].wind_from),
"now_wind": lambda: wind_text(hours[0].wind_speed, settings.wind),
"high": lambda: f"Max {degrees(summary.high, t)}",
"low": lambda: f"Min {degrees(summary.low, t)}",
"rain_start": lambda: rain_start_text(summary, zone),
}
for k, i in enumerate(PICKS):
if i >= len(hours):
break
hour = hours[i]
makers |= {
f"pick_time_{k}": lambda h=hour: f"{local(h.time):%H:%M}",
f"pick_name_{k}": lambda h=hour, k=k: "Now" if k == 0 else f"{local(h.time):%H:%M}",
f"pick_icon_{k}": lambda h=hour: icon(h.symbol),
f"pick_temp_{k}": lambda h=hour: degrees(h.temperature, t),
f"pick_rain_{k}": lambda h=hour: rain_amount(h.rain, settings),
f"pick_barb_{k}": lambda h=hour: wind(h),
}
pairs = [hours[i : i + 2] for i in range(0, len(hours), 2)]
wet = [sum(h.rain for h in pair if h.rain >= forecast.WET) for pair in pairs]
pair_top = max([2 * 2.0, *wet]) # like the hourly bars: at least 2 mm per hour
for k, (pair, mm) in enumerate(zip(pairs, wet, strict=True)):
makers |= {
f"pair_hour_{k}": lambda h=pair[0]: f"{local(h.time):%H}",
f"pair_icon_{k}": lambda h=pair[0]: icon(h.symbol),
f"pair_temp_{k}": lambda h=pair[0]: degrees(h.temperature, t),
f"pair_bar_{k}": lambda mm=mm: rain_bar(mm, pair_top),
f"pair_mm_{k}": lambda mm=mm: rain_text(mm, unit),
}
for i, hour in enumerate(hours):
makers |= {
f"bar_{i}": lambda h=hour: rain_bar(h.rain, top),
Expand All @@ -285,19 +362,17 @@ def wind(hour: Hour):
makers[f"icon_{i // 2}"] = lambda h=hour: icon(h.symbol)
for k in range(len(hours) // 3):
part = hours[3 * k : 3 * k + 3]
low, high = (degrees(f(h.temperature for h in part), t) for f in (min, max))
mm = rain_text(sum(h.rain for h in part if h.rain >= forecast.WET), unit)
mm = sum(h.rain for h in part if h.rain >= forecast.WET)
# The icon of the wettest hour, so it matches the rain shown under it; when dry,
# the middle hour's, like the wind.
# the middle hour's.
wettest = max(part, key=lambda h: h.rain)
shown = wettest if wettest.rain >= forecast.WET else part[1]
end = part[-1].time + timedelta(hours=1)
makers |= {
f"step_{k}": lambda p=part, e=end: f"{local(p[0].time):%H}–{end_hour(e, zone)}",
f"step_icon_{k}": lambda h=shown: icon(h.symbol),
f"step_temp_{k}": lambda lo=low, hi=high: lo if lo == hi else f"{lo[:-1]}–{hi}",
f"step_rain_{k}": lambda mm=mm: f"{mm} {rain_unit(settings)}" if mm else "",
f"step_barb_{k}": lambda p=part: wind(p[1]), # the wind at the middle hour
f"step_temp_{k}": lambda p=part: degrees(max(h.temperature for h in p), t),
f"step_rain_{k}": lambda mm=mm: rain_amount(mm, settings),
}
wanted = PLUGIN.layout(context.layout, settings).blocks
return {name: make() for name, make in makers.items() if name in wanted}
Expand Down Expand Up @@ -346,9 +421,13 @@ def _sample() -> Weather:
layouts=LAYOUTS,
layout_titles={
"hours_12": "Next 12 hours",
"small": "Small: right now",
"three_rows": "Three rows: now, +3 and +6 hours",
"three_columns": "Three columns: now, +3 and +6 hours",
"now_and_today": "Right now and today",
"six_hours": "Every 2 hours",
"steps_3h": "Every 3 hours",
"now": "Right now, large",
"small": "Small: right now",
"portrait_hours": "Upright: hour by hour",
"portrait_now": "Upright: right now",
},
Expand Down
Loading
Loading