feat(shcedule): add channels list

This commit is contained in:
2024-08-15 00:53:57 +03:00
parent 05161749e8
commit 320fbbcaa5
5 changed files with 103 additions and 10 deletions

View File

@@ -32,12 +32,35 @@ def mount(app: FastAPI):
},
)
@app.get("/schedule/tag/{tag}", response_class=HTMLResponse)
async def get_schedule_tag(request: Request, tag: str, live: bool = False):
tag_value = TagUtil.parse_tag(tag)
schedule_api: ScheduleApi = request.app.state.schedule_api
channels = await schedule_api.get_channels()
responses = [
await schedule_api.get_channel_schedule(channel, tag_value.date)
for channel in channels
]
return templates.TemplateResponse(
request=request,
name="schedule.html",
context={
"version": __version__,
"tag_util": TagUtil,
"datetime": datetime,
"channels": channels,
"response": responses[0],
"responses": responses,
"live": live,
},
)
@app.get("/schedule/{channel}", response_class=RedirectResponse)
async def get_schedule_default(channel: str):
async def get_channel_default(channel: str):
return RedirectResponse(f"{channel}/tag/today")
@app.get("/schedule/{channel}/tag/{tag}", response_class=HTMLResponse)
async def get_schedule_tag(request: Request, channel: str, tag: str):
async def get_channel_tag(request: Request, channel: str, tag: str):
tag_value = TagUtil.parse_tag(tag)
schedule_api: ScheduleApi = request.app.state.schedule_api
if tag_value.type == TagType.DAY:
@@ -46,7 +69,7 @@ def mount(app: FastAPI):
raise ValueError(tag)
return templates.TemplateResponse(
request=request,
name="schedule.html",
name="channel.html",
context={
"version": __version__,
"tag_util": TagUtil,

View File

@@ -5,3 +5,10 @@ td {
tr.live {
font-weight: bold;
}
.title {
margin-top: 0.5rem;
font-style: italic;
font-weight: bold;
font-size: 120%;
}

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>Программа | {{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/schedule/style.css?v={{version}}">
<link rel="icon"
href="/static/common/favicon.ico"
type="image/x-icon">
</head>
<body class="app-container">
<h3>
<a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button"
href="../..">⬆️</a>
<span>{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
</h3>
<table>
<thead>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
{% for value in response.values %}
<tr class="{{'live' if value.live else ''}}">
<td>{{value.start.strftime('%H:%M')}}</td>
<td>{{(value.end - value.start) | timedelta_format}}</td>
<td>{{value.label}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>

View File

@@ -7,7 +7,7 @@
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>Программа | {{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</title>
<title>ТВ</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
@@ -23,12 +23,12 @@
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button"
href="../..">⬆️</a>
<span>{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<span>Прямые трансляции | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
</h3>
<table>
<table class="{{'live' if live else ''}}">
<thead>
<tr>
<td></td>
@@ -37,13 +37,25 @@
</tr>
</thead>
<tbody>
{% for value in response.values %}
<tr class="{{'live' if value.live else ''}}">
{% for response in responses %}
{% set values = (response.values|selectattr('live') if live else response.values)|list %}
{% if values|length > 0 %}
<tr>
<td colspan="3">
<div class="title">{{response.channel.name}}</div>
</td>
<td></td>
<td></td>
</tr>
{% for value in values %}
<tr class="{{'live' if not live and value.live else ''}}">
<td>{{value.start.strftime('%H:%M')}}</td>
<td>{{(value.end - value.start) | timedelta_format}}</td>
<td>{{value.label}}</td>
</tr>
{% endfor %}
{% endif %}
{% endfor %}
</tbody>
</table>
</body>

View File

@@ -17,9 +17,9 @@ CHANNEL_LIST = [
"arena",
"futbol-1",
"futbol-2",
"futbol-2",
"futbol-3",
"strana",
"planeta",
# "planeta",
]