feat(easel): add base template

This commit is contained in:
2026-04-12 17:37:36 +03:00
parent f303d0e1f4
commit ad8144df37
15 changed files with 433 additions and 442 deletions

12
.editorconfig Normal file
View File

@@ -0,0 +1,12 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false

View File

@@ -1,19 +1,29 @@
{ {
"folders": [ "folders": [
{ {
"path": "." "path": ".",
} },
], ],
"settings": { "settings": {
"python.testing.pytestArgs": ["tests", "-s"], "python.testing.pytestArgs": ["tests", "-s"],
"python.testing.unittestEnabled": false, "python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true, "python.testing.pytestEnabled": true,
"python-envs.pythonProjects": [
{
"path": ".",
"envManager": "ms-python.python:poetry",
"packageManager": "ms-python.python:poetry",
},
],
"files.associations": {
"*.html": "jinja-html",
},
"files.exclude": { "files.exclude": {
"**/__pycache__": true "**/__pycache__": true,
}, },
"terminal.integrated.env.linux": { "terminal.integrated.env.linux": {
"PYTHONPATH": "${workspaceFolder}" "PYTHONPATH": "${workspaceFolder}",
} },
}, },
"launch": { "launch": {
"version": "0.2.1", "version": "0.2.1",
@@ -27,9 +37,9 @@
"gallery.main:app", "gallery.main:app",
"--reload", "--reload",
"--log-config", "--log-config",
"gallery/logging.yaml" "gallery/logging.yaml",
] ],
} },
] ],
} },
} }

View File

@@ -29,7 +29,7 @@ def mount(app: FastAPI):
async def get_section_list(request: Request): async def get_section_list(request: Request):
return templates.TemplateResponse( return templates.TemplateResponse(
request=request, request=request,
name="index.html", name="root_index.html",
context={ context={
"version": __version__, "version": __version__,
"sections": SECTIONS, "sections": SECTIONS,

View File

@@ -47,25 +47,32 @@ app
*/ */
.app-container { .app-container {
display: flex; display: flex;
flex-direction: column; flex-direction: row;
flex-wrap: nowrap; flex-wrap: nowrap;
align-items: center; align-items: stretch;
}
.app-menu {
display: flex;
flex-direction: column;
margin: 0.5rem;
}
.app-content {
display: flex;
flex: 1;
flex-direction: column;
} }
.app-header { .app-header {
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
} gap: 0.5rem;
.app-title {
display: flex;
justify-content: center; justify-content: center;
flex-grow: 1;
} }
.app-link-home > * { .app-link-home > * {
margin-left: 2rem;
width: 2rem; width: 2rem;
height: 2rem; height: 2rem;
background-image: url("/static/common/gallery.png"); background-image: url("/static/common/gallery.png");
@@ -81,6 +88,7 @@ app
ul.app-list { ul.app-list {
list-style: none; list-style: none;
padding-left: 0;
} }
ul.app-list > li { ul.app-list > li {

View File

@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block 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>{% block title %}{% endblock %}</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="icon"
href="/static/common/favicon.ico?v={{version}}"
type="image/x-icon">
{% endblock %}
</head>
<body class="app-container">
<div class="app-menu">
<a class="app-link-home"
href="/">
<div></div>
</a>
</div>
<div class="app-content">
<h3 class="app-header">
{% block header %}{% endblock %}</span>
</h3>
{% block content %}{% endblock %}
<div class="app-footer">
{% block footer %}{% endblock %}
</div>
</div>
</body>
</html>

View File

@@ -1,41 +0,0 @@
<!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>Информация</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="icon"
href="/static/common/favicon.ico?v={{version}}"
type="image/x-icon">
</head>
<body class="app-container">
<h3 class="app-header">
<a class="app-link-home"
href="/">
<div></div>
</a>
<div class="app-title">
<span>Информация</span>
</div>
</h3>
<ul class="app-list">
{% for section in sections %}
<li>
<a href="{{section.link}}">
<span class="icon"
style="background-image: url(/static/{{section.link}}/{{section.link}}.png);"></span>
<span>{{section.title}}</span>
</a>
</li>
{% endfor %}
</ul>
</body>
</html>

View File

@@ -0,0 +1,21 @@
{% extends "base.html" %}
{% block title %}Информация{% endblock %}
{% block head %}
{{ super() }}
{% endblock %}
{% block header %}Информация{% endblock %}
{% block content %}
<ul class="app-list">
{% for section in sections %}
<li>
<a href="{{section.link}}">
<span class="icon"
style="background-image: url(/static/{{section.link}}/{{section.link}}.png);"></span>
<span>{{section.title}}</span>
</a>
</li>
{% endfor %}
</ul>
{% endblock %}

View File

@@ -17,7 +17,12 @@ from .filters import timedelta_format
def mount(app: FastAPI): def mount(app: FastAPI):
base_dir = Path(__file__).parent base_dir = Path(__file__).parent
app.mount("/static/schedule", StaticFiles(directory=base_dir / "static")) app.mount("/static/schedule", StaticFiles(directory=base_dir / "static"))
templates = Jinja2Templates(directory=base_dir / "templates") templates = Jinja2Templates(
directory=[
base_dir.parent / "common/templates",
base_dir / "templates",
]
)
templates.env.filters["timedelta_format"] = timedelta_format templates.env.filters["timedelta_format"] = timedelta_format
@app.get("/schedule", response_class=HTMLResponse) @app.get("/schedule", response_class=HTMLResponse)

View File

@@ -1,40 +1,28 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}
Программа | {{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}
<head> {% endblock %}
<meta charset="UTF-8"> {% block head %}
<meta name="viewport" {{ super() }}
content="width=device-width, initial-scale=1.0"> <link rel="stylesheet"
<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}}"> href="/static/schedule/style.css?v={{version}}">
<link rel="icon" <link rel="icon"
href="/static/schedule/favicon.ico?v={{version}}" href="/static/schedule/favicon.ico?v={{version}}"
type="image/x-icon"> type="image/x-icon">
</head> {% endblock %}
<body class="app-container"> {% block header %}
<h3 class="app-header"> <a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
<a class="app-link-home"
href="/">
<div></div>
</a>
<div class="app-title">
<a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a> href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button" <a class="button"
href="../..">⬆️</a> href="../..">⬆️</a>
<span>{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</span> <span>{{response.channel.name}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button" <a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a> href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
</div> {% endblock %}
</h3>
<table> {% block content %}
<table>
<thead> <thead>
<tr> <tr>
<td></td> <td></td>
@@ -51,7 +39,5 @@
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</body> {% endblock %}
</html>

View File

@@ -1,38 +1,21 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}ТВ{% endblock %}
{% block head %}
<head> {{ super() }}
<meta charset="UTF-8"> <link rel="stylesheet"
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>ТВ</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/schedule/style.css?v={{version}}"> href="/static/schedule/style.css?v={{version}}">
<link rel="icon" <link rel="icon"
href="/static/schedule/favicon.ico?v={{version}}" href="/static/schedule/favicon.ico?v={{version}}"
type="image/x-icon"> type="image/x-icon">
</head> {% endblock %}
<body class="app-container"> {% block header %}Телепрограмма{% endblock %}
<h3 class="app-header">
<a class="app-link-home" {% block content %}
href="/"> <ul class="app-list">
<div></div>
</a>
<div class="app-title">
<span>Телепрограмма</span>
</div>
</h3>
<ul class="app-list">
<li style="margin-bottom: 0.25rem; font-weight: bold;"><a href="schedule/tag/today">Все</a></li> <li style="margin-bottom: 0.25rem; font-weight: bold;"><a href="schedule/tag/today">Все</a></li>
{% for channel in channels %} {% for channel in channels %}
<li><a href="schedule/{{channel.id}}">{{channel.name}}</a></li> <li><a href="schedule/{{channel.id}}">{{channel.name}}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</body> {% endblock %}
</html>

View File

@@ -1,39 +1,28 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}
{{'Прямые трансляции' if live else 'Программа'}} | {{response.date.strftime('%a, %d %B %Y')}}
<head> {% endblock %}
<meta charset="UTF-8"> {% block head %}
<meta name="viewport" {{ super() }}
content="width=device-width, initial-scale=1.0"> <link rel="stylesheet"
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>ТВ</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/schedule/style.css?v={{version}}"> href="/static/schedule/style.css?v={{version}}">
<link rel="icon" <link rel="icon"
href="/static/schedule/favicon.ico?v={{version}}" href="/static/schedule/favicon.ico?v={{version}}"
type="image/x-icon"> type="image/x-icon">
</head> {% endblock %}
<body class="app-container"> {% block header %}
<h3 class="app-header"> <a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
<a class="app-link-home"
href="/">
<div></div>
</a>
<div class="app-title">
<a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a> href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button" <a class="button"
href="..">⬆️</a> href="..">⬆️</a>
<span>{{'Прямые трансляции' if live else 'Программа'}} | {{response.date.strftime('%a, %d %B %Y')}}</span> <span>{{'Прямые трансляции' if live else 'Программа'}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button" <a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a> href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
</div> {% endblock %}
</h3>
{% block content %}
<div>
<table class="{{'live' if live else ''}}"> <table class="{{'live' if live else ''}}">
<thead> <thead>
<tr> <tr>
@@ -64,6 +53,5 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
</body> </div>
{% endblock %}
</html>

View File

@@ -19,7 +19,12 @@ from .filters import cloudness_icon, wind_direction_icon
def mount(app: FastAPI): def mount(app: FastAPI):
base_dir = Path(__file__).parent base_dir = Path(__file__).parent
app.mount("/static/weather", StaticFiles(directory=base_dir / "static")) app.mount("/static/weather", StaticFiles(directory=base_dir / "static"))
templates = Jinja2Templates(directory=base_dir / "templates") templates = Jinja2Templates(
directory=[
base_dir.parent / "common/templates",
base_dir / "templates",
]
)
templates.env.filters["wind_direction_icon"] = wind_direction_icon templates.env.filters["wind_direction_icon"] = wind_direction_icon
templates.env.filters["cloudness_icon"] = cloudness_icon templates.env.filters["cloudness_icon"] = cloudness_icon

View File

@@ -1,37 +1,20 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Погода{% endblock %}
{% block head %}
<head> {{ super() }}
<meta charset="UTF-8"> <link rel="stylesheet"
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>Погода</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/weather/style.css?v={{version}}"> href="/static/weather/style.css?v={{version}}">
<link rel="icon" <link rel="icon"
href="/static/weather/favicon.ico?v={{version}}" href="/static/weather/favicon.ico?v={{version}}"
type="image/x-icon"> type="image/x-icon">
</head> {% endblock %}
<body class="app-container"> {% block header %}Погода{% endblock %}
<h3 class="app-header">
<a class="app-link-home" {% block content %}
href="/"> <ul class="app-list">
<div></div>
</a>
<div class="app-title">
<span>Погода</span>
</div>
</h3>
<ul class="app-list">
{% for location in locations %} {% for location in locations %}
<li><a href="weather/{{location.id}}">{{location.name}}</a></li> <li><a href="weather/{{location.id}}">{{location.name}}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</body> {% endblock %}
</html>

View File

@@ -1,44 +1,32 @@
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en"> {% block title %}Погода | {{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}{% endblock %}
{% block head %}
<head> {{ super() }}
<meta charset="UTF-8"> <link rel="stylesheet"
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible"
content="ie=edge">
<title>Погода | {{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}</title>
<link rel="stylesheet"
href="/static/common/style.css?v={{version}}">
<link rel="stylesheet"
href="/static/weather/style.css?v={{version}}"> href="/static/weather/style.css?v={{version}}">
<link rel="icon" <link rel="icon"
href="/static/weather/favicon.ico?v={{version}}" href="/static/weather/favicon.ico?v={{version}}"
type="image/x-icon"> type="image/x-icon">
</head> {% endblock %}
<body class="app-container"> {% block header %}
<h3 class="app-header"> {% if response.period == 'day' %}
<a class="app-link-home" <a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="/">
<div></div>
</a>
<div class="app-title">
{% if response.period == 'day' %}
<a class="button {{'disabled' if response.date == datetime.date.today() else ''}}"
href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a> href="../tag/{{tag_util.create_tag('day', response.date, -1)}}">⬅️</a>
<a class="button" <a class="button"
href="../tag/days-10">⬆️</a> href="../tag/days-10">⬆️</a>
<span>{{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}</span> <span>{{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
<a class="button" <a class="button"
href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a> href="../tag/{{tag_util.create_tag('day', response.date, 1)}}">➡️</a>
{% endif %} {% endif %}
{% if response.period == 'days' %} {% if response.period == 'days' %}
<span>{{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}</span> <span>{{response.location}} | {{response.date.strftime('%a, %d %B %Y')}}</span>
{% endif %} {% endif %}
</div> {% endblock %}
</h3>
<table> {% block content %}
<div>
<table style="margin: auto;">
<tbody> <tbody>
<!-- date --> <!-- date -->
<tr> <tr>
@@ -179,6 +167,5 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
</body> </div>
{% endblock %}
</html>

View File

@@ -29,19 +29,25 @@ class MatchTvApi(ScheduleApi):
async def get_channel_schedule( async def get_channel_schedule(
self, channel_id: str, date: datetime.date self, channel_id: str, date: datetime.date
) -> Schedule: ) -> Schedule:
endpoint = f"channel/{channel_id}/tvguide?date={date:%d-%m-%Y}" endpoint = f"tvguide/{channel_id}?date={date:%Y%m%d}"
data = await self.SOURCE.request(endpoint) data = await self.SOURCE.request(endpoint)
soup = BeautifulSoup(data, features="html.parser") soup = BeautifulSoup(data, features="html.parser")
values = [] values = []
channel_name = soup.select_one(".caption__heading").text.split("|")[0].strip() channel_name = (
soup.select_one(".p-tv-guide-header__title")
.text.replace("Телепрограмма ", "")
.strip()
)
current_day = datetime.datetime.combine( current_day = datetime.datetime.combine(
date.today(), datetime.datetime.min.time() date.today(), datetime.datetime.min.time()
) )
end = current_day + datetime.timedelta(days=1, hours=6) end = current_day + datetime.timedelta(days=1, hours=6)
prev_value: ScheduleValue | None = None prev_value: ScheduleValue | None = None
for item in soup.select(".teleprogram-schedule .teleprogram-schedule__item"): for item in soup.select(
title = item.select_one(".teleprogram-item__title").text.strip() ".p-tv-guide-schedule-channel-carcass__transmissions .p-tv-guide-schedule-channel-transmission"
time_str = item.select_one(".teleprogram-item__time").text.strip() ):
title = item.select_one(".p-tv-guide-schedule-channel-transmission__title").text.strip()
time_str = item.select_one(".p-tv-guide-schedule-channel-transmission__time-block").text.strip()
hours, minutes = map(int, time_str.split(":")) hours, minutes = map(int, time_str.split(":"))
item_date = current_day.replace(hour=hours, minute=minutes) item_date = current_day.replace(hour=hours, minute=minutes)
if prev_value is not None and item_date.hour < prev_value.start.hour: if prev_value is not None and item_date.hour < prev_value.start.hour: