Skip to content

Commit

Permalink
Add content and copyright attribution to Markdown output
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Mar 31, 2024
1 parent 2725137 commit 9f7b18d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Expand Up @@ -8,6 +8,7 @@ Development
- Add support for Python 3.12
- Dependencies: Update from docopt to docopt-ng
- Fix translation "sehr hoch" => "intensive"
- Add content and copyright attribution to Markdown output


2023-04-09 0.8.6
Expand Down
15 changes: 8 additions & 7 deletions apicast/api.py
Expand Up @@ -10,10 +10,11 @@
from apicast import __appname__, __version__
from apicast.core import (
DwdBeeflightForecast,
apicast_link,
apicast_name,
dwd_copyright,
dwd_source,
producer_link,
producer_name,
dwd_link,
dwd_name,
)
from apicast.format import Formatter

Expand Down Expand Up @@ -90,8 +91,8 @@ def index():
<div style="float: left">
{description}
<ul>
<li>Producer: <a href="{producer_link}">{producer_name}</a></li>
<li>Source: <a href="{dwd_source}">DWD » Freizeitgärtner » Gartenwetter » Prognose des Bienenfluges</a></li>
<li>Producer: <a href="{apicast_link}">{apicast_name}</a></li>
<li>Source: <a href="{dwd_link}">DWD » Freizeitgärtner » Gartenwetter » Prognose des Bienenfluges</a></li>
<li>Data copyright: {dwd_copyright}</li>
</ul>
</div>
Expand Down Expand Up @@ -172,9 +173,9 @@ def beeflight_forecast_by_slug(
def make_json_response(data: List[Dict], location: str = None):
return {
"meta": {
"source": dwd_source,
"producer": f"{producer_name} - {producer_link}",
"copyright": dwd_copyright,
"source": f"{dwd_name} - {dwd_link}",
"producer": f"{apicast_name} - {apicast_link}",
},
"location": {
"slug": location,
Expand Down
9 changes: 5 additions & 4 deletions apicast/core.py
Expand Up @@ -22,10 +22,11 @@
from apicast import __appname__, __version__

user_agent = f"{__appname__}/{__version__}"
dwd_source = "https://www.dwd.de/DE/leistungen/biene_flug/bienenflug.html"
dwd_copyright = "© Deutscher Wetterdienst (DWD), Agricultural Meteorology Department"
producer_name = "Hiveeyes Apicast"
producer_link = "https://github.com/hiveeyes/apicast"
dwd_copyright = "© Deutscher Wetterdienst (DWD)"
dwd_name = "DWD Agricultural Meteorology Department"
dwd_link = "https://www.dwd.de/DE/leistungen/biene_flug/bienenflug.html"
apicast_name = "Hiveeyes Apicast"
apicast_link = "https://github.com/hiveeyes/apicast"


@dataclasses.dataclass
Expand Down
13 changes: 13 additions & 0 deletions apicast/format.py
Expand Up @@ -9,6 +9,8 @@
import tabulate
from dateparser import parse as parsedate

from apicast.core import apicast_link, apicast_name, dwd_copyright, dwd_link, dwd_name


class Formatter:
"""
Expand Down Expand Up @@ -96,4 +98,15 @@ def table_markdown(self):
)
)

print()
print(
f"""
{dwd_copyright}
[{dwd_name}] • [{apicast_name}]
[{dwd_name}]: {dwd_link}
[{apicast_name}]: {apicast_link}
""".strip()
)

return buffer.getvalue()
25 changes: 24 additions & 1 deletion test/test_format.py
@@ -1,3 +1,4 @@
import marko
import pytest

from apicast.core import Result, State, Station
Expand All @@ -20,6 +21,22 @@
footnote="© Deutscher Wetterdienst, erstellt 30.03.2024 05:00 UTC. Alle Angaben ohne Gewähr!",
)

markdown_reference = """
### Prognose des Bienenfluges in Potsdam
| Datum | morgens | mittags | abends |
|:----------|:----------|:----------|:---------|
| Sa 30.03. | mittel | sehr hoch | hoch |
| So 31.03. | mittel | hoch | hoch |
| Mo 01.04. | mittel | hoch | mittel |
© Deutscher Wetterdienst (DWD)
[DWD Agricultural Meteorology Department] • [Hiveeyes Apicast]
[DWD Agricultural Meteorology Department]: https://www.dwd.de/DE/leistungen/biene_flug/bienenflug.html
[Hiveeyes Apicast]: https://github.com/hiveeyes/apicast
""".lstrip()


@pytest.fixture
def formatter() -> Formatter:
Expand Down Expand Up @@ -58,4 +75,10 @@ def test_format_translate(formatter: Formatter):


def test_format_markdown(formatter: Formatter):
assert "sehr strong" not in formatter.table_markdown()
markdown = formatter.table_markdown()
assert markdown_reference == markdown
assert "Datum" in markdown
assert "sehr strong" not in markdown

html = marko.convert(markdown)
assert html.startswith("<h3>Prognose des Bienenfluges in Potsdam</h3>")

0 comments on commit 9f7b18d

Please sign in to comment.