From b3d88997ebbb0f1e33bd0651dc87b6f14e9a685f Mon Sep 17 00:00:00 2001 From: shmyga Date: Thu, 25 Jul 2024 15:51:27 +0300 Subject: [PATCH] feat(app): add html weather view --- gismeteo/api.py | 14 +- gismeteo/app.py | 21 +-- gismeteo/dateutil.py | 30 ++++ gismeteo/mock/__init__.py | 25 +++ .../mock/data/weather.html | 0 gismeteo/mock/data/weather.json | 1 + gismeteo/parser.py | 4 +- gismeteo/route/__init__.py | 0 gismeteo/route/api.py | 12 ++ .../{custom_doc.py => route/doc/__init__.py} | 5 +- .../route/doc/static}/redoc.standalone.js | 0 .../route/doc/static}/swagger-ui-bundle.js | 0 .../route/doc/static}/swagger-ui.css | 0 gismeteo/route/view/__init__.py | 43 +++++ gismeteo/route/view/filters.py | 27 ++++ gismeteo/route/view/static/favicon.ico | Bin 0 -> 15406 bytes gismeteo/route/view/static/index.js | 0 gismeteo/route/view/static/style.css | 81 ++++++++++ gismeteo/route/view/templates/weather.html | 151 ++++++++++++++++++ poetry.lock | 2 +- pyproject.toml | 1 + tests/test_api.py | 10 +- 22 files changed, 393 insertions(+), 34 deletions(-) create mode 100644 gismeteo/dateutil.py create mode 100644 gismeteo/mock/__init__.py rename tests/tomorrow.html => gismeteo/mock/data/weather.html (100%) create mode 100644 gismeteo/mock/data/weather.json create mode 100644 gismeteo/route/__init__.py create mode 100644 gismeteo/route/api.py rename gismeteo/{custom_doc.py => route/doc/__init__.py} (90%) rename {static/docs => gismeteo/route/doc/static}/redoc.standalone.js (100%) rename {static/docs => gismeteo/route/doc/static}/swagger-ui-bundle.js (100%) rename {static/docs => gismeteo/route/doc/static}/swagger-ui.css (100%) create mode 100644 gismeteo/route/view/__init__.py create mode 100644 gismeteo/route/view/filters.py create mode 100644 gismeteo/route/view/static/favicon.ico create mode 100644 gismeteo/route/view/static/index.js create mode 100644 gismeteo/route/view/static/style.css create mode 100644 gismeteo/route/view/templates/weather.html diff --git a/gismeteo/api.py b/gismeteo/api.py index ea6b9c7..1261c43 100644 --- a/gismeteo/api.py +++ b/gismeteo/api.py @@ -3,9 +3,10 @@ from typing import Any, Dict, List, NamedTuple import aiohttp from bs4 import BeautifulSoup +from . import dateutil from .location import LOCATION_BUNDLE -from .parser import ROW_PARSERS, OneDayParser +from .parser import ROW_PARSERS, ONE_DAY_PARSER class WeatherValue(NamedTuple): @@ -32,7 +33,7 @@ class GismeteoApi: def _parse_oneday(self, data: str) -> List[WeatherValue]: result: List[Dict[str, Any]] = [] soup = BeautifulSoup(data, features="html.parser") - widget = OneDayParser().parse_widget(soup) + widget = ONE_DAY_PARSER.parse_widget(soup) for parser in ROW_PARSERS: for index, value in enumerate(parser.parse_row(widget)): while len(result) < index + 1: @@ -40,12 +41,7 @@ class GismeteoApi: result[index][parser.KEY] = value return [WeatherValue(**item) for item in result] - async def today(self, location_id: str) -> List[WeatherValue]: + async def get_day(self, location_id: str, date: datetime.date) -> List[WeatherValue]: location = LOCATION_BUNDLE.parse(location_id) - data = await self._request(f"weather-{location}/today") - return self._parse_oneday(data) - - async def tomorrow(self, location_id: str) -> List[WeatherValue]: - location = LOCATION_BUNDLE.parse(location_id) - data = await self._request(f"weather-{location}/tomorrow") + data = await self._request(f"weather-{location}/{dateutil.dump(date)}") return self._parse_oneday(data) diff --git a/gismeteo/app.py b/gismeteo/app.py index d6a1b29..c902d1a 100644 --- a/gismeteo/app.py +++ b/gismeteo/app.py @@ -1,26 +1,17 @@ +import locale from os import environ import uvicorn from fastapi import FastAPI -from gismeteo import custom_doc -from gismeteo.api import GismeteoApi +from gismeteo.route import api, doc, view +locale.setlocale(locale.LC_TIME, "ru_RU.UTF-8") app = FastAPI(docs_url=None, redoc_url=None) -custom_doc.apply(app) - - -@app.get("/") -async def root(): - return {} - - -@app.get("/weather/{location_id}") -async def get_weather(location_id: str): - api = GismeteoApi() - result = await api.today(location_id) - return [item._asdict() for item in result] +doc.mount(app) +api.mount(app) +view.mount(app) def run(): diff --git a/gismeteo/dateutil.py b/gismeteo/dateutil.py new file mode 100644 index 0000000..b020b31 --- /dev/null +++ b/gismeteo/dateutil.py @@ -0,0 +1,30 @@ +import datetime + +import dateparser +import dateparser.date_parser + + +def parse(value: str) -> datetime.date: + if value == "today" or value == "mock": + return datetime.date.today() + elif value == "tomorrow": + return datetime.date.today() + datetime.timedelta(days=1) + elif value.endswith("-day"): + days = int(value.split("-")[0]) - 1 + return datetime.date.today() + datetime.timedelta(days=days) + else: + date = dateparser.parse(value) + if date is None: + raise ValueError(value) + return date.date() + + +def dump(date: datetime.date) -> str: + today = datetime.date.today() + days = (date - today).days + if days == 0: + return "today" + elif days == 1: + return "tomorrow" + else: + return f"{days + 1}-day" diff --git a/gismeteo/mock/__init__.py b/gismeteo/mock/__init__.py new file mode 100644 index 0000000..edd05d8 --- /dev/null +++ b/gismeteo/mock/__init__.py @@ -0,0 +1,25 @@ +import json +from pathlib import Path +from typing import List + +import dateparser + +from gismeteo.api import WeatherValue + + +class MockData: + + @property + def html(self) -> str: + return (Path(__file__).parent / "data/weather.html").read_text() + + @property + def values(self) -> List[WeatherValue]: + data = json.loads((Path(__file__).parent / "data/weather.json").read_text()) + return [ + WeatherValue(**{**item, "date": dateparser.parse(item["date"])}) + for item in data + ] + + +MOCK_DATA = MockData() diff --git a/tests/tomorrow.html b/gismeteo/mock/data/weather.html similarity index 100% rename from tests/tomorrow.html rename to gismeteo/mock/data/weather.html diff --git a/gismeteo/mock/data/weather.json b/gismeteo/mock/data/weather.json new file mode 100644 index 0000000..55c462e --- /dev/null +++ b/gismeteo/mock/data/weather.json @@ -0,0 +1 @@ +[{"date":"2024-07-25T00:00:00","cloudness":"Ясно","temperature":14,"wind_speed":1,"wind_gust":1,"wind_direction":"С","precipitation":0.0,"pressure":739,"humidity":85},{"date":"2024-07-25T03:00:00","cloudness":"Ясно","temperature":13,"wind_speed":1,"wind_gust":2,"wind_direction":"СЗ","precipitation":0.0,"pressure":739,"humidity":92},{"date":"2024-07-25T06:00:00","cloudness":"Малооблачно, без осадков","temperature":14,"wind_speed":1,"wind_gust":2,"wind_direction":"СЗ","precipitation":0.0,"pressure":738,"humidity":89},{"date":"2024-07-25T09:00:00","cloudness":"Малооблачно, без осадков","temperature":23,"wind_speed":3,"wind_gust":5,"wind_direction":"С","precipitation":0.0,"pressure":738,"humidity":58},{"date":"2024-07-25T12:00:00","cloudness":"Малооблачно, без осадков","temperature":26,"wind_speed":3,"wind_gust":6,"wind_direction":"СЗ","precipitation":0.0,"pressure":738,"humidity":47},{"date":"2024-07-25T15:00:00","cloudness":"Облачно, без осадков","temperature":26,"wind_speed":2,"wind_gust":6,"wind_direction":"С","precipitation":0.0,"pressure":737,"humidity":46},{"date":"2024-07-25T18:00:00","cloudness":"Малооблачно, небольшой дождь","temperature":24,"wind_speed":3,"wind_gust":7,"wind_direction":"СВ","precipitation":0.3,"pressure":737,"humidity":54},{"date":"2024-07-25T21:00:00","cloudness":"Ясно","temperature":19,"wind_speed":1,"wind_gust":5,"wind_direction":"С","precipitation":0.0,"pressure":738,"humidity":80}] \ No newline at end of file diff --git a/gismeteo/parser.py b/gismeteo/parser.py index 21b928c..39ffefc 100644 --- a/gismeteo/parser.py +++ b/gismeteo/parser.py @@ -6,9 +6,7 @@ from bs4 import Tag from .core import BaseWidgetParser, RowParser - -class OneDayParser(BaseWidgetParser): - SELECT = ".widget.widget-oneday .widget-items" +ONE_DAY_PARSER = BaseWidgetParser(".widget.widget-oneday .widget-items") class DateParser(RowParser[datetime.datetime]): diff --git a/gismeteo/route/__init__.py b/gismeteo/route/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gismeteo/route/api.py b/gismeteo/route/api.py new file mode 100644 index 0000000..ae291df --- /dev/null +++ b/gismeteo/route/api.py @@ -0,0 +1,12 @@ +from fastapi import FastAPI + +from gismeteo import dateutil +from gismeteo.api import GismeteoApi + + +def mount(app: FastAPI): + @app.get("/api/weather/{location}/{date}") + async def get_weather(location: str, date: str): + api = GismeteoApi() + result = await api.get_day(location, dateutil.parse(date)) + return [item._asdict() for item in result] diff --git a/gismeteo/custom_doc.py b/gismeteo/route/doc/__init__.py similarity index 90% rename from gismeteo/custom_doc.py rename to gismeteo/route/doc/__init__.py index 63a0603..fdba2b2 100644 --- a/gismeteo/custom_doc.py +++ b/gismeteo/route/doc/__init__.py @@ -8,9 +8,10 @@ from fastapi.openapi.docs import ( from fastapi.staticfiles import StaticFiles -def apply(app: FastAPI): +def mount(app: FastAPI): app.mount( - "/docs/static", StaticFiles(directory=Path(__file__).parent.parent / "static/docs") + "/docs/static", + StaticFiles(directory=Path(__file__).parent / "static"), ) @app.get("/docs", include_in_schema=False) diff --git a/static/docs/redoc.standalone.js b/gismeteo/route/doc/static/redoc.standalone.js similarity index 100% rename from static/docs/redoc.standalone.js rename to gismeteo/route/doc/static/redoc.standalone.js diff --git a/static/docs/swagger-ui-bundle.js b/gismeteo/route/doc/static/swagger-ui-bundle.js similarity index 100% rename from static/docs/swagger-ui-bundle.js rename to gismeteo/route/doc/static/swagger-ui-bundle.js diff --git a/static/docs/swagger-ui.css b/gismeteo/route/doc/static/swagger-ui.css similarity index 100% rename from static/docs/swagger-ui.css rename to gismeteo/route/doc/static/swagger-ui.css diff --git a/gismeteo/route/view/__init__.py b/gismeteo/route/view/__init__.py new file mode 100644 index 0000000..a4bfa1b --- /dev/null +++ b/gismeteo/route/view/__init__.py @@ -0,0 +1,43 @@ +import datetime +from pathlib import Path + +from fastapi import FastAPI, Request +from fastapi.responses import HTMLResponse, RedirectResponse +from fastapi.staticfiles import StaticFiles +from fastapi.templating import Jinja2Templates + +from gismeteo import dateutil +from gismeteo.api import GismeteoApi +from gismeteo.mock import MOCK_DATA + +from .filters import cloudness_icon, wind_direction_icon + + +def mount(app: FastAPI): + base_dir = Path(__file__).parent + app.mount("/static", StaticFiles(directory=base_dir / "static"), name="static") + templates = Jinja2Templates(directory=base_dir / "templates") + templates.env.filters["wind_direction_icon"] = wind_direction_icon + templates.env.filters["cloudness_icon"] = cloudness_icon + + @app.get("/weather/{location}") + async def get_weather_base(location: str): + return RedirectResponse(f"{location}/today") + + @app.get("/weather/{location}/{date}", response_class=HTMLResponse) + async def get_weather(request: Request, location: str, date: str): + if date == "mock": + values = MOCK_DATA.values + else: + api = GismeteoApi() + values = await api.get_day(location, dateutil.parse(date)) + return templates.TemplateResponse( + request=request, + name="weather.html", + context={ + "datetime": datetime, + "location": location, + "date": dateutil.parse(date), + "values": values, + }, + ) diff --git a/gismeteo/route/view/filters.py b/gismeteo/route/view/filters.py new file mode 100644 index 0000000..92f7e67 --- /dev/null +++ b/gismeteo/route/view/filters.py @@ -0,0 +1,27 @@ +def wind_direction_icon(wind_direction: str) -> str: + return { + "С": "🡫", + "СВ": "🡯", + "В": "🡨", + "ЮВ": "🡬", + "Ю": "🡡", + "ЮЗ": "🡭", + "З": "🡪", + "СЗ": "🡦", + "штиль": "", + }.get(wind_direction, wind_direction) + + +def cloudness_icon(cloudness: str) -> str: + return { + "Ясно": "☀️", + "Малооблачно, без осадков": "🌤️", + "Облачно, без осадков": "⛅", + "Малооблачно, небольшой дождь": "🌦️", + "Пасмурно, без осадков": "☁️", + "Облачно, небольшой дождь": "🌧️", + "Облачно, дождь": "🌧️", + "Облачно, небольшой дождь, гроза": "⛈️", + "Малооблачно, дождь": "🌦️", + "Пасмурно, небольшой дождь": "🌧️", + }.get(cloudness, cloudness) diff --git a/gismeteo/route/view/static/favicon.ico b/gismeteo/route/view/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..a283ecbb19c12721c2eba06930c07b51354f6565 GIT binary patch literal 15406 zcmeHNd2m!k8h=S7C?JOt0c%~e>#n-HXt|5WAFdEW!W9)(K;yXxO0nxwu2o<}1Omw> z1SObbauW_$6pvLF2_=UKXgHEc<_gww7=(aPLLfkxOfoaye!m$z>6yHFZ-x*ktMaOP zx?lJAeZSw=*X!wSMF~;Dlz{^kjw6-X*C@*UilRhDdfx9Gq$tIlch5aPmEW!?yCW3k zPL^R6*6`$Wr1yldKwl31Gy=*Y=k?5*HLF)cL&I8^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9h41a-?tZ5r=2n@PoJP5t9`f|K1zPUDJ5qe}EvBMjFPL+0d>8jL zOgViWxI@Qdo$#NgIDZMP;()lgU?~+BCe!MoRGODp?e&e5xr=YpKi1M>wGb%3VB|2q z4-^f%mG7TKS@I(m@Hp9EDHvR3Ef{>1-%q+@em56He8~4@78Dn+oce4oRraAxk2VQsBm|aA}XBSgmAnTd#!0)ly PQv*FU&{G3lt%3go^wSY@ literal 0 HcmV?d00001 diff --git a/gismeteo/route/view/static/index.js b/gismeteo/route/view/static/index.js new file mode 100644 index 0000000..e69de29 diff --git a/gismeteo/route/view/static/style.css b/gismeteo/route/view/static/style.css new file mode 100644 index 0000000..2062ca2 --- /dev/null +++ b/gismeteo/route/view/static/style.css @@ -0,0 +1,81 @@ +body { + font-size: 1.5rem; +} + +h3 { + margin: 0.5rem 0; +} + +a.button { + text-decoration: none; + color: inherit; +} + +.button.disabled { + pointer-events: none; + cursor: default; + color: gray; +} + +table { + /* width: 100%; */ + table-layout: fixed; + border-collapse: collapse; +} + +table, +th, +td { + /* border: 1px solid rgba(0, 0, 0, 0.2); */ + text-align: center; +} + +td { + padding: 0.1rem 0.4rem; +} + +.header { + font-size: 1rem; + text-align: left; +} + +.date { + font-size: 1.5rem; + background: rgba(0, 0, 0, 0.1); +} + +.date.now { + background: rgba(0, 128, 255, 0.2); +} + +.cloudness .icon { + font-size: 2rem; +} + +.temperature.positive .value { + color: orangered; +} + +.temperature.negative .value { + color: blue; +} + +.wind .direction { + font-size: 1rem; +} + +.wind .gust { + font-size: 1rem; +} + +.precipitation .value { + color: blue; +} + +.pressure .value { + color: blueviolet; +} + +.humidity .value { + color: blue; +} diff --git a/gismeteo/route/view/templates/weather.html b/gismeteo/route/view/templates/weather.html new file mode 100644 index 0000000..8ec055c --- /dev/null +++ b/gismeteo/route/view/templates/weather.html @@ -0,0 +1,151 @@ + + + + + + + + Weather - {{date.strftime('%a, %d %B %Y')}} + + + + + +

+ 🡨 + {{date.strftime('%a, %d %B %Y')}} + 🡪 +

+ + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + + + + + + {% for value in values %} + + {% endfor %} + + +
+ {{value.date.strftime('%H:%M')}} +
+ Облачность +
+ {{value.cloudness | cloudness_icon}} +
+ Температура, °C +
+ {{value.temperature}} +
+ Направление ветра +
+ {{value.wind_direction | wind_direction_icon}} + {{value.wind_direction}} +
+ Скорость ветра, м/с +
+ {{value.wind_speed}} + {% if value.wind_gust != value.wind_speed %} + + ({{value.wind_gust}}) + + {% endif %} +
+ Осадки, мм +
+ {{value.precipitation or ' '}} +
+ Давление, мм рт. ст. +
+ {{value.pressure}} +
+ Влажность, % +
+ {{value.humidity}} +
+ + + + \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 058aa4f..2239456 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1795,4 +1795,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "1fd060f04380ffd2a390e2940573687736a03a7d668bc774f4942d9b63bcac3d" +content-hash = "6940ed3fa5467b63dde6410fcb427cbcf93c4366f967e07cf24601d51b43a28f" diff --git a/pyproject.toml b/pyproject.toml index 7ccbffa..0499746 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ dateparser = "^1.2.0" [tool.poetry.group.app.dependencies] fastapi = "^0.111.1" +jinja2 = "^3.1.4" [tool.poetry.group.test.dependencies] pytest = "^8.3.1" diff --git a/tests/test_api.py b/tests/test_api.py index b20d8fe..08b6a79 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,8 +1,9 @@ -from pathlib import Path +import datetime import pytest from gismeteo.api import GismeteoApi +from gismeteo.mock import MOCK_DATA @pytest.fixture(name="gismeteo_api", scope="module") @@ -10,13 +11,14 @@ def gismeteo_api_fixture() -> GismeteoApi: api = GismeteoApi() async def _request(endpoint: str) -> str: - target = endpoint.split("/")[-1] - return (Path(__file__).parent / f"{target}.html").read_text() + return MOCK_DATA.html api._request = _request return api async def test_api(gismeteo_api: GismeteoApi): - result = await gismeteo_api.tomorrow("zmiyevka") + result = await gismeteo_api.get_day( + "zmiyevka", datetime.date.today() + datetime.timedelta(days=1) + ) assert len(result) == 8