feat(easel): add api link button to views
test / test (push) Successful in 59s

This commit is contained in:
2026-09-30 20:56:17 +03:00
parent 4fc1c8c8e5
commit ad8f29c5ef
7 changed files with 51 additions and 14 deletions
+23 -11
View File
@@ -1,4 +1,3 @@
import datetime
from pathlib import Path
from urllib import parse
@@ -13,9 +12,7 @@ from gallery.easel.depends.schedule import (
ScheduleApiDepends,
ScheduleGroupChannelsDepends,
)
from gallery.sketch.bundle import ApiBundle
from gallery.sketch.schedule.api import ScheduleApi
from gallery.sketch.schedule.model import Schedule
from ..common.utils.template import build_templates
from .filters import timedelta_format
@@ -52,12 +49,6 @@ async def get_schedule_index(request: AppRequest, provider: str | None = None, q
)
async def _get_group_schedule(api: ApiBundle, channels: list[tuple[str, str]], date: datetime.date) -> list[Schedule]:
return [
await api.get_api(ScheduleApi, provider).get_schedule(channel_id, date) for provider, channel_id in channels
]
@router.get("/group/{group_id}", response_class=RedirectResponse)
async def get_group_default(group_id: str):
return RedirectResponse(f"{parse.quote(group_id)}/today")
@@ -72,7 +63,16 @@ async def get_group(request: AppRequest, channels: ScheduleGroupChannelsDepends,
return templates.TemplateResponse(
request=request,
name="group.html",
context={"responses": responses},
context={
"responses": responses,
"api_route": "/".join(
[
"/api/schedule/group",
request.path_params["group_id"],
request.path_params["date"],
]
),
},
)
@@ -87,5 +87,17 @@ async def get_channel(request: AppRequest, schedule_api: ScheduleApiDepends, cha
return templates.TemplateResponse(
request=request,
name="channel.html",
context={"response": response},
context={
"response": response,
"api_route": (
"/".join(
[
"/api/schedule",
request.path_params["provider"],
request.path_params["channel"],
request.path_params["date"],
]
)
),
},
)
@@ -10,6 +10,9 @@ locale=request.state.language)}}
{% block header %}
<app-link href="/schedule"
icon="tv">{{_("TV program")}}</app-link>
<app-link target="_blank"
href="{{ api_route }}"
icon="filetype-json"></app-link>
{% endblock %}
{% block content %}
@@ -44,7 +47,8 @@ locale=request.state.language)}}
{% for value in response.values %}
<tr class="{{'d-none' if (live and not value.live) else 'table-success' if (not live and value.live) else ''}}">
<td>
<span>{{value.start.strftime('%H:%M')}}</span>&nbsp;<span class="small ms-1">({{(value.end - value.start) | timedelta_format}})</span>
<span>{{value.start.strftime('%H:%M')}}</span>&nbsp;<span class="small ms-1">({{(value.end - value.start) |
timedelta_format}})</span>
</td>
<td>{{value.label}}</td>
</tr>
@@ -9,6 +9,9 @@
{% block header %}
<app-link href="/schedule"
icon="tv">{{_("TV program")}}</app-link>
<app-link target="_blank"
href="{{ api_route }}"
icon="filetype-json"></app-link>
{% endblock %}
{% block content %}
+12 -1
View File
@@ -37,7 +37,18 @@ def build_weather_response(request: AppRequest, response: WeatherResponse):
return templates.TemplateResponse(
request=request,
name="weather.html",
context={"response": response},
context={
"response": response,
"api_route": "/".join(
[
"/api/weather",
request.path_params["provider"],
request.path_params["location"],
response.period,
request.path_params.get("date") or request.path_params.get("days") or "",
]
),
},
)
@@ -7,6 +7,9 @@ locale=request.state.language)}}{% endblock %}
{% block header %}
<app-link href="/weather"
icon="brightness-high">{{_("Weather")}}</app-link>
<app-link target="_blank"
href="{{ api_route }}"
icon="filetype-json"></app-link>
{% endblock %}
{% block content %}
+2 -1
View File
@@ -29,6 +29,7 @@ class YandexTVApi(ScheduleApi):
return self.channel_parser.parse(data)
async def get_schedule(self, channel_id: str, date: datetime.date) -> Schedule:
endpoint = f"{self.lr}/channel/{channel_id}?date={date:%Y-%m-%d}"
channel_path_part = "channel" if "-" in channel_id else "channels"
endpoint = f"{self.lr}/{channel_path_part}/{channel_id}?date={date:%Y-%m-%d}"
data = await self.source.request(endpoint)
return self.schedule_parser.parse(ScheduleData(date, channel_id, data))
+3
View File
@@ -48,4 +48,7 @@
&.bi-cast {
mask-image: url(bootstrap-icons/icons/cast.svg);
}
&.bi-filetype-json {
mask-image: url(bootstrap-icons/icons/filetype-json.svg);
}
}