| @@ -1,30 +1,94 @@ | |||
| #!/usr/bin/env python3 | |||
| from typing import Union | |||
| from babel.dates import format_time | |||
| from .utils import _ | |||
| from kosmorrolib import ( | |||
| EventType, | |||
| MoonPhaseType, | |||
| ObjectIdentifier, | |||
| Event, | |||
| SeasonType, | |||
| LunarEclipseType, | |||
| ) | |||
| from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event | |||
| def from_event(event: Event) -> Union[None, str]: | |||
| string = None | |||
| match event.event_type: | |||
| case EventType.OPPOSITION: | |||
| string, details = ( | |||
| _("%s is in opposition") % from_object(event.objects[0].identifier), | |||
| None, | |||
| ) | |||
| case EventType.CONJUNCTION: | |||
| string, details = ( | |||
| _("%s and %s are in conjunction") | |||
| % ( | |||
| from_object(event.objects[0].identifier), | |||
| from_object(event.objects[1].identifier), | |||
| ), | |||
| None, | |||
| ) | |||
| case EventType.OCCULTATION: | |||
| string, details = ( | |||
| _("%s occults %s") | |||
| % ( | |||
| from_object(event.objects[0].identifier), | |||
| from_object(event.objects[1].identifier), | |||
| ), | |||
| None, | |||
| ) | |||
| case EventType.MAXIMAL_ELONGATION: | |||
| string, details = ( | |||
| _("Elongation of %s is maximal") | |||
| % from_object(event.objects[0].identifier), | |||
| lambda e: "{:.3n}°".format(e.details["deg"]), | |||
| ) | |||
| case EventType.PERIGEE: | |||
| string, details = ( | |||
| _("%s is at its periapsis") % from_object(event.objects[0].identifier), | |||
| None, | |||
| ) | |||
| case EventType.APOGEE: | |||
| string, details = ( | |||
| _("%s is at its apoapsis") % from_object(event.objects[0].identifier), | |||
| None, | |||
| ) | |||
| case EventType.SEASON_CHANGE: | |||
| match event.details["season"]: | |||
| case SeasonType.MARCH_EQUINOX: | |||
| string = _("March equinox") | |||
| case SeasonType.JUNE_SOLSTICE: | |||
| string = _("June solstice") | |||
| case SeasonType.SEPTEMBER_EQUINOX: | |||
| string = _("September equinox") | |||
| case _: | |||
| string = _("December solstice") | |||
| def from_event(event: Event, with_description: bool = True) -> Union[None, str]: | |||
| string, details = { | |||
| EventType.OPPOSITION: (_("%s is in opposition"), None), | |||
| EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None), | |||
| EventType.OCCULTATION: (_("%s occults %s"), None), | |||
| EventType.MAXIMAL_ELONGATION: ( | |||
| _("Elongation of %s is maximal"), | |||
| lambda e: "{:.3n}°".format(e.details["deg"]), | |||
| ), | |||
| EventType.PERIGEE: (_("%s is at its periapsis"), None), | |||
| EventType.APOGEE: (_("%s is at its apoapsis"), None), | |||
| }.get(event.event_type, (None, None)) | |||
| details = None | |||
| case EventType.LUNAR_ECLIPSE: | |||
| match event.details["type"]: | |||
| case LunarEclipseType.TOTAL: | |||
| string = _("Total lunar eclipse until %(hour)s") % { | |||
| "hour": format_time(event.end_time, "short") | |||
| } | |||
| if string is None: | |||
| return None | |||
| case LunarEclipseType.PENUMBRAL: | |||
| string = _("Penumbral lunar eclipse until %(hour)s") % { | |||
| "hour": format_time(event.end_time, "short") | |||
| } | |||
| case LunarEclipseType.PARTIAL: | |||
| string = _("Partial lunar eclipse until %(hour)s") % { | |||
| "hour": format_time(event.end_time, "short") | |||
| } | |||
| string = string % tuple([from_object(o.identifier) for o in event.objects]) | |||
| details = None | |||
| case _: | |||
| return None | |||
| if details is not None and with_description: | |||
| if details is not None: | |||
| return "%s (%s)" % (string, details(event)) | |||
| return string | |||
| @@ -8,7 +8,7 @@ msgid "" | |||
| msgstr "" | |||
| "Project-Id-Version: PROJECT VERSION\n" | |||
| "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" | |||
| "POT-Creation-Date: 2025-03-28 20:36+0100\n" | |||
| "POT-Creation-Date: 2025-04-15 23:15+0200\n" | |||
| "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | |||
| "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |||
| "Language-Team: LANGUAGE <LL@li.org>\n" | |||
| @@ -208,109 +208,140 @@ msgstr "" | |||
| msgid "The given Plus Code seems to be a short code, please provide a full code." | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:11 | |||
| #: kosmorro/i18n/strings.py:21 | |||
| #, python-format | |||
| msgid "%s is in opposition" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:12 | |||
| #: kosmorro/i18n/strings.py:26 | |||
| #, python-format | |||
| msgid "%s and %s are in conjunction" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:13 | |||
| #: kosmorro/i18n/strings.py:35 | |||
| #, python-format | |||
| msgid "%s occults %s" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:15 | |||
| #: kosmorro/i18n/strings.py:44 | |||
| #, python-format | |||
| msgid "Elongation of %s is maximal" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:18 | |||
| #: kosmorro/i18n/strings.py:50 | |||
| #, python-format | |||
| msgid "%s is at its periapsis" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:19 | |||
| #: kosmorro/i18n/strings.py:55 | |||
| #, python-format | |||
| msgid "%s is at its apoapsis" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:35 | |||
| #: kosmorro/i18n/strings.py:61 | |||
| msgid "March equinox" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:63 | |||
| msgid "June solstice" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:65 | |||
| msgid "September equinox" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:67 | |||
| msgid "December solstice" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:73 | |||
| #, python-format | |||
| msgid "Total lunar eclipse until %(hour)s" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:78 | |||
| #, python-format | |||
| msgid "Penumbral lunar eclipse until %(hour)s" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:83 | |||
| #, python-format | |||
| msgid "Partial lunar eclipse until %(hour)s" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:99 | |||
| msgid "New Moon" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:36 | |||
| #: kosmorro/i18n/strings.py:100 | |||
| msgid "Waxing Crescent" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:37 | |||
| #: kosmorro/i18n/strings.py:101 | |||
| msgid "First Quarter" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:38 | |||
| #: kosmorro/i18n/strings.py:102 | |||
| msgid "Waxing Gibbous" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:39 | |||
| #: kosmorro/i18n/strings.py:103 | |||
| msgid "Full Moon" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:40 | |||
| #: kosmorro/i18n/strings.py:104 | |||
| msgid "Waning Gibbous" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:41 | |||
| #: kosmorro/i18n/strings.py:105 | |||
| msgid "Last Quarter" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:42 | |||
| #: kosmorro/i18n/strings.py:106 | |||
| msgid "Waning Crescent" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:53 | |||
| #: kosmorro/i18n/strings.py:117 | |||
| msgid "Sun" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:54 | |||
| #: kosmorro/i18n/strings.py:118 | |||
| msgid "Moon" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:55 | |||
| #: kosmorro/i18n/strings.py:119 | |||
| msgid "Mercury" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:56 | |||
| #: kosmorro/i18n/strings.py:120 | |||
| msgid "Venus" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:57 | |||
| #: kosmorro/i18n/strings.py:121 | |||
| msgid "Earth" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:58 | |||
| #: kosmorro/i18n/strings.py:122 | |||
| msgid "Mars" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:59 | |||
| #: kosmorro/i18n/strings.py:123 | |||
| msgid "Jupiter" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:60 | |||
| #: kosmorro/i18n/strings.py:124 | |||
| msgid "Saturn" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:61 | |||
| #: kosmorro/i18n/strings.py:125 | |||
| msgid "Uranus" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:62 | |||
| #: kosmorro/i18n/strings.py:126 | |||
| msgid "Neptune" | |||
| msgstr "" | |||
| #: kosmorro/i18n/strings.py:63 | |||
| #: kosmorro/i18n/strings.py:127 | |||
| msgid "Pluto" | |||
| msgstr "" | |||
| @@ -0,0 +1,30 @@ | |||
| #!/usr/bin/env python3 | |||
| from .utils import ( | |||
| execute, | |||
| KOSMORRO, | |||
| ) | |||
| def test_lunar_eclipse_wording(): | |||
| result = execute(KOSMORRO + ["--date=2025-03-14"]) | |||
| assert result.successful | |||
| assert "4:07\u202fAM Total lunar eclipse until 9:50\u202fAM" in result.stdout | |||
| def test_seasons(): | |||
| result = execute(KOSMORRO + ["--date=2025-03-20"]) | |||
| assert result.successful | |||
| assert "9:01\u202fAM March equinox" in result.stdout | |||
| result = execute(KOSMORRO + ["--date=2025-06-21"]) | |||
| assert result.successful | |||
| assert "2:42\u202fAM June solstice" in result.stdout | |||
| result = execute(KOSMORRO + ["--date=2025-09-22"]) | |||
| assert result.successful | |||
| assert "6:19\u202fPM September equinox" in result.stdout | |||
| result = execute(KOSMORRO + ["--date=2025-12-21"]) | |||
| assert result.successful | |||
| assert "3:03\u202fPM December solstice" in result.stdout | |||