Move emojis into one place

Closes: #113
This commit is contained in:
Edward Betts 2024-01-16 15:32:39 +00:00
parent 8047cb67fe
commit 4638069e51
9 changed files with 41 additions and 11 deletions

View file

@ -13,8 +13,7 @@ def get_events(filepath: str) -> list[Event]:
date=item["from"], date=item["from"],
end_date=item["to"], end_date=item["to"],
name="accommodation", name="accommodation",
title="🧳" title=(
+ (
f'{item["location"]} Airbnb' f'{item["location"]} Airbnb'
if item.get("operator") == "airbnb" if item.get("operator") == "airbnb"
else item["name"] else item["name"]

View file

@ -42,7 +42,7 @@ def get_birthdays(from_date: date, filepath: str) -> list[Event]:
Event( Event(
date=bday.replace(year=bday.year + offset), date=bday.replace(year=bday.year + offset),
name="birthday", name="birthday",
title=f'🎈 {entity["label"]} ({display_age})', title=f'{entity["label"]} ({display_age})',
) )
) )

View file

@ -36,7 +36,7 @@ def build_events(events: list[Event]) -> list[dict[str, typing.Any]]:
assert e.title and e.end_date assert e.title and e.end_date
item = { item = {
"allDay": True, "allDay": True,
"title": e.display_title, "title": e.title_with_emoji,
"start": e.as_date.isoformat(), "start": e.as_date.isoformat(),
"end": (e.end_as_date + one_day).isoformat(), "end": (e.end_as_date + one_day).isoformat(),
"url": e.url, "url": e.url,
@ -66,7 +66,7 @@ def build_events(events: list[Event]) -> list[dict[str, typing.Any]]:
end = (e.end_as_date if e.end_date else e.as_date) + one_day end = (e.end_as_date if e.end_date else e.as_date) + one_day
item = { item = {
"allDay": not e.has_time, "allDay": not e.has_time,
"title": e.display_title, "title": e.title_with_emoji,
"start": e.date.isoformat(), "start": e.date.isoformat(),
"end": end.isoformat(), "end": end.isoformat(),
} }

View file

@ -51,7 +51,7 @@ def get_list(filepath: str) -> list[Event]:
name="conference", name="conference",
date=conf.start, date=conf.start,
end_date=conf.end, end_date=conf.end,
title=f"🎤 {conf.display_name}", title=conf.display_name,
url=conf.url, url=conf.url,
going=conf.going, going=conf.going,
) )

View file

@ -363,7 +363,7 @@ async def get_data(
if not dt: if not dt:
continue continue
rocket_name = f'🚀{launch["rocket"]}: {launch["mission_name"] or "[no mission]"}' rocket_name = f'{launch["rocket"]}: {launch["mission_name"] or "[no mission]"}'
e = Event(name="rocket", date=dt, title=rocket_name) e = Event(name="rocket", date=dt, title=rocket_name)
events.append(e) events.append(e)

View file

@ -21,7 +21,7 @@ def get_events(data_dir: str) -> list[Event]:
date=start, date=start,
end_date=end, end_date=end,
name="meetup", name="meetup",
title="👥" + item_event["title"], title=item_event["title"],
url=item_event["eventUrl"], url=item_event["eventUrl"],
) )
events.append(e) events.append(e)

View file

@ -93,6 +93,23 @@ class Holiday:
date: datetime.date date: datetime.date
emojis = {
"market": "🧺",
"us_presidential_election": "🗳️🇺🇸",
"bus_route_closure": "🚌❌",
"meetup": "👥",
"dinner": "🍷",
"party": "🍷",
"ba_voucher": "✈️",
"accommodation": "🏨", # alternative: 🧳
"flight": "✈️",
"conference": "🎤",
"rocket": "🚀",
"birthday": "🎈",
"waste_schedule": "🗑️",
}
@dataclass @dataclass
class Event: class Event:
"""Event.""" """Event."""
@ -182,3 +199,17 @@ class Event:
def display_title(self) -> str: def display_title(self) -> str:
"""Name for display.""" """Name for display."""
return self.title or self.name return self.title or self.name
@property
def emoji(self) -> str | None:
"""Emoji."""
return emojis.get(self.name)
@property
def title_with_emoji(self) -> str | None:
"""Title with optional emoji at the start."""
title = self.title or self.name
if title is None:
return None
emoji = self.emoji
return f"{emoji} {title}" if emoji else title

View file

@ -95,7 +95,7 @@ def parse(root: lxml.html.HtmlElement) -> list[Event]:
Event( Event(
name="waste_schedule", name="waste_schedule",
date=uk_time(d, time(6, 30)), date=uk_time(d, time(6, 30)),
title="🗑️ Backwell: " + ", ".join(services), title="Backwell: " + ", ".join(services),
) )
for d, services in by_date.items() for d, services in by_date.items()
] ]
@ -208,6 +208,6 @@ async def get_bristol_gov_uk(
by_date[d].append(service) by_date[d].append(service)
return [ return [
Event(name="waste_schedule", date=d, title="🗑️ Bristol: " + ", ".join(services)) Event(name="waste_schedule", date=d, title="Bristol: " + ", ".join(services))
for d, services in by_date.items() for d, services in by_date.items()
] ]

View file

@ -184,7 +184,7 @@
<div class="col-md-7 text-start"> <div class="col-md-7 text-start">
{% if event.url %}<a href="{{ event.url }}">{% endif %} {% if event.url %}<a href="{{ event.url }}">{% endif %}
{{ event_labels.get(event.name) or event.name }} {{ event_labels.get(event.name) or event.name }}
{%- if event.title -%}: {{ event.title }}{% endif %} {%- if event.title -%}: {{ event.title_with_emoji }}{% endif %}
{% if event.url %}</a>{% endif %} {% if event.url %}</a>{% endif %}
</div> </div>
<div class="col-md-1{{ cell_bg }}"> <div class="col-md-1{{ cell_bg }}">