diff --git a/gallery/easel/route/view/schedule/templates/channel.html b/gallery/easel/route/view/schedule/templates/channel.html index d3acb47..c401c7e 100644 --- a/gallery/easel/route/view/schedule/templates/channel.html +++ b/gallery/easel/route/view/schedule/templates/channel.html @@ -50,7 +50,14 @@ locale=request.state.language)}} {{value.start.strftime('%H:%M')}} ({{(value.end - value.start) | timedelta_format}}) - {{value.label}} + + {% if value.category %} + + {% endif %} + {{value.label}} + {% endfor %} diff --git a/gallery/easel/route/view/schedule/templates/group.html b/gallery/easel/route/view/schedule/templates/group.html index ea54cd2..ff49046 100644 --- a/gallery/easel/route/view/schedule/templates/group.html +++ b/gallery/easel/route/view/schedule/templates/group.html @@ -53,7 +53,14 @@ {{value.start.strftime('%H:%M')}} ({{(value.end - value.start) | timedelta_format}}) - {{value.label}} + + {% if value.category %} + + {% endif %} + {{value.label}} + {% endfor %} diff --git a/gallery/painting/matchtv/parser.py b/gallery/painting/matchtv/parser.py index be33d2d..dfe30a0 100644 --- a/gallery/painting/matchtv/parser.py +++ b/gallery/painting/matchtv/parser.py @@ -6,6 +6,7 @@ from typing import Any from gallery.sketch.parse.core import ParsedContext, Parser from gallery.sketch.parse.json import JSONContextParser from gallery.sketch.schedule.model import Channel, Schedule, ScheduleValue +from gallery.sketch.schedule.parse.category import CATEGORY_PARSER from . import PROVIDER @@ -28,6 +29,7 @@ class MatchTVScheduleParser(JSONContextParser[ScheduleData, Schedule]): def extract(self, data: ParsedContext[ScheduleData, Any]) -> Schedule: channel_data = data.data["result"]["channels"][0] channel = Channel(id=channel_data["alias"], name=channel_data["name"], provider=PROVIDER) + default_category = CATEGORY_PARSER.parse(channel.name) values = [] start = datetime.datetime.combine(data.context.date, datetime.time.min) end = start + datetime.timedelta(days=1, hours=6) @@ -41,7 +43,8 @@ class MatchTVScheduleParser(JSONContextParser[ScheduleData, Schedule]): start += datetime.timedelta(days=1) item_date += datetime.timedelta(days=1) live = "Прямая трансляция" in title - value = ScheduleValue(start=item_date, end=end, label=title, live=live) + category = CATEGORY_PARSER.parse(title) or default_category + value = ScheduleValue(start=item_date, end=end, label=title, category=category, live=live) values.append(value) if prev_value is not None: prev_value.end = item_date diff --git a/gallery/painting/yandextv/parser.py b/gallery/painting/yandextv/parser.py index 04cca63..0836729 100644 --- a/gallery/painting/yandextv/parser.py +++ b/gallery/painting/yandextv/parser.py @@ -5,10 +5,11 @@ from typing import Any from bs4 import Tag from gallery.sketch.parse.core import ParsedContext, ParseError +from gallery.sketch.parse.html import HTMLContextParser from gallery.sketch.parse.json import JSONParser from gallery.sketch.schedule.model import Channel, Schedule, ScheduleValue +from gallery.sketch.schedule.parse.category import CATEGORY_PARSER -from ...sketch.parse.html import HTMLContextParser from . import PROVIDER @@ -37,7 +38,8 @@ class YandexTVScheduleParser(HTMLContextParser[ScheduleData, Schedule]): current_day += datetime.timedelta(days=1) item_date += datetime.timedelta(days=1) live = item.select_one(".channel-schedule__info .icon_live") is not None - value = ScheduleValue(start=item_date, end=end, label=title, live=live) + category = CATEGORY_PARSER.parse(title) + value = ScheduleValue(start=item_date, end=end, label=title, category=category, live=live) values.append(value) if prev_value is not None: prev_value.end = item_date diff --git a/gallery/sketch/schedule/parse/__init__.py b/gallery/sketch/schedule/parse/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gallery/sketch/schedule/parse/category.py b/gallery/sketch/schedule/parse/category.py new file mode 100644 index 0000000..a95405c --- /dev/null +++ b/gallery/sketch/schedule/parse/category.py @@ -0,0 +1,28 @@ +from gallery.sketch.parse.core import Parser + + +class CategoryParser(Parser[str, str | None]): + CATEGORY_MAP = { + "гандбол": "handball", + "хоккей": "hockey", + "бильярд": "billiards", + "волейбол": "volleyball", + "футбол": "soccer", + "футзал": "futsal", + "баскетбол": "basketball", + "плавание": "swimming", + "автоспорт": "motorsport", + "регби": "rugby", + "велоспорт": "cycling", + "гимнастика": "gymnastics", + } + + def parse(self, data: str) -> str | None: + data = data.lower() + for k, v in self.CATEGORY_MAP.items(): + if k in data: + return v + return None + + +CATEGORY_PARSER = CategoryParser() diff --git a/static/src/index.ts b/static/src/index.ts index 518e85c..623943b 100644 --- a/static/src/index.ts +++ b/static/src/index.ts @@ -4,5 +4,7 @@ import "./app/common/tooltips"; import "./app/components/app-link"; import "./app/schedule"; import "./app/weather"; -import { init } from "./lib/weather-icons"; -init("/static/weather-icons/icons"); +import { init as scheduleIconsInit } from "./lib/schedule-icons"; +import { init as weatherIconsInit } from "./lib/weather-icons"; +weatherIconsInit("/static/weather-icons/icons"); +scheduleIconsInit("/static/schedule-icons/icons"); diff --git a/static/src/lib/schedule-icons/icons/basketball.svg b/static/src/lib/schedule-icons/icons/basketball.svg new file mode 100644 index 0000000..3dfab1e --- /dev/null +++ b/static/src/lib/schedule-icons/icons/basketball.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/billiards.svg b/static/src/lib/schedule-icons/icons/billiards.svg new file mode 100644 index 0000000..8b2fbff --- /dev/null +++ b/static/src/lib/schedule-icons/icons/billiards.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/cycling.svg b/static/src/lib/schedule-icons/icons/cycling.svg new file mode 100644 index 0000000..0ccd5b2 --- /dev/null +++ b/static/src/lib/schedule-icons/icons/cycling.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/futsal.svg b/static/src/lib/schedule-icons/icons/futsal.svg new file mode 100644 index 0000000..f7f6d2e --- /dev/null +++ b/static/src/lib/schedule-icons/icons/futsal.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/gymnastics.svg b/static/src/lib/schedule-icons/icons/gymnastics.svg new file mode 100644 index 0000000..537422a --- /dev/null +++ b/static/src/lib/schedule-icons/icons/gymnastics.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/handball.svg b/static/src/lib/schedule-icons/icons/handball.svg new file mode 100644 index 0000000..af92ee0 --- /dev/null +++ b/static/src/lib/schedule-icons/icons/handball.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/hockey.svg b/static/src/lib/schedule-icons/icons/hockey.svg new file mode 100644 index 0000000..565916f --- /dev/null +++ b/static/src/lib/schedule-icons/icons/hockey.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/motorsport.svg b/static/src/lib/schedule-icons/icons/motorsport.svg new file mode 100644 index 0000000..ddfb4d3 --- /dev/null +++ b/static/src/lib/schedule-icons/icons/motorsport.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/rugby.svg b/static/src/lib/schedule-icons/icons/rugby.svg new file mode 100644 index 0000000..594d3ab --- /dev/null +++ b/static/src/lib/schedule-icons/icons/rugby.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/soccer.svg b/static/src/lib/schedule-icons/icons/soccer.svg new file mode 100644 index 0000000..f7f6d2e --- /dev/null +++ b/static/src/lib/schedule-icons/icons/soccer.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/swimming.svg b/static/src/lib/schedule-icons/icons/swimming.svg new file mode 100644 index 0000000..2c0f78d --- /dev/null +++ b/static/src/lib/schedule-icons/icons/swimming.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/icons/volleyball.svg b/static/src/lib/schedule-icons/icons/volleyball.svg new file mode 100644 index 0000000..dcfe437 --- /dev/null +++ b/static/src/lib/schedule-icons/icons/volleyball.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/static/src/lib/schedule-icons/index.ts b/static/src/lib/schedule-icons/index.ts new file mode 100644 index 0000000..88fa31c --- /dev/null +++ b/static/src/lib/schedule-icons/index.ts @@ -0,0 +1,6 @@ +import { ScheduleIconElement } from "./schedule-icons"; + +export const init = (iconsPath: string) => { + ScheduleIconElement.iconsPath = iconsPath; + customElements.define("schedule-icon", ScheduleIconElement); +}; diff --git a/static/src/lib/schedule-icons/sass/schedule-icons.scss b/static/src/lib/schedule-icons/sass/schedule-icons.scss new file mode 100644 index 0000000..83c6c9b --- /dev/null +++ b/static/src/lib/schedule-icons/sass/schedule-icons.scss @@ -0,0 +1,19 @@ +schedule-icon { + display: inline-block; + text-transform: none; + line-height: 1; + vertical-align: 0.125em; + width: 1em; + height: 1em; + + mask-size: contain; + mask-position: 50%; + mask-repeat: no-repeat; + color: currentColor; + + > svg { + path { + fill: currentColor; + } + } +} diff --git a/static/src/lib/schedule-icons/schedule-icons.ts b/static/src/lib/schedule-icons/schedule-icons.ts new file mode 100644 index 0000000..ec75446 --- /dev/null +++ b/static/src/lib/schedule-icons/schedule-icons.ts @@ -0,0 +1,19 @@ +export class ScheduleIconElement extends HTMLElement { + static iconsPath = "./icons"; + static observedAttributes = ["icon"]; + + constructor() { + super(); + const icon = this.getAttribute("icon"); + if (icon) { + this.icon = icon; + } + } + + set icon(value: string) { + const src = `${ScheduleIconElement.iconsPath}/${value}.svg`; + fetch(src) + .then((response) => (response.ok ? response.text() : "")) + .then((data) => (this.innerHTML = data)); + } +} diff --git a/static/src/lib/weather-icons/weather-icon.ts b/static/src/lib/weather-icons/weather-icon.ts index 2b50ef2..ab6ce1c 100644 --- a/static/src/lib/weather-icons/weather-icon.ts +++ b/static/src/lib/weather-icons/weather-icon.ts @@ -11,7 +11,6 @@ export class WeatherIconElement extends HTMLElement { } set icon(value: string) { - console.log('!', WeatherIconElement.iconsPath); const src = `${WeatherIconElement.iconsPath}/wi-${value}.svg`; fetch(src) .then((response) => response.text()) diff --git a/static/src/main.scss b/static/src/main.scss index 101d191..165c248 100644 --- a/static/src/main.scss +++ b/static/src/main.scss @@ -2,6 +2,7 @@ @import "./lib/bootstrap"; @import "./lib/bootstrap-icons"; @import "./lib/weather-icons"; +@import "./lib/schedule-icons/sass/schedule-icons.scss"; @import "./styles/weather.scss"; @import "./styles/app"; diff --git a/static/webpack.config.ts b/static/webpack.config.ts index ba331d1..bae597c 100644 --- a/static/webpack.config.ts +++ b/static/webpack.config.ts @@ -61,6 +61,11 @@ const config: webpack.Configuration = { from: "./src/lib/weather-icons/icons/*.svg", to: "weather-icons/icons/[name][ext]", }, + // schedule icons + { + from: "./src/lib/schedule-icons/icons/*.svg", + to: "schedule-icons/icons/[name][ext]", + }, // bootstrap icons { from: "./node_modules/bootstrap-icons/icons/*.svg",