|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +from typing import Union |
3 | 4 | from .utils import _ |
4 | 5 |
|
5 | 6 | from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event |
6 | 7 |
|
7 | 8 |
|
8 | | -def from_event(event: Event, with_description: bool = True) -> str: |
| 9 | +def from_event(event: Event, with_description: bool = True) -> Union[None, str]: |
9 | 10 | string, details = { |
10 | 11 | EventType.OPPOSITION: (_("%s is in opposition"), None), |
11 | 12 | EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None), |
12 | 13 | EventType.OCCULTATION: (_("%s occults %s"), None), |
13 | | - EventType.MAXIMAL_ELONGATION: ( |
14 | | - _("Elongation of %s is maximal"), |
15 | | - ( |
16 | | - "{:.3n}°".format(event.details["deg"]) |
17 | | - if type(event.details) is dict |
18 | | - else event.details |
19 | | - ), |
20 | | - ), |
| 14 | + EventType.MAXIMAL_ELONGATION: (_("Elongation of %s is maximal"), lambda e: "{:.3n}°".format(e.details["deg"])), |
21 | 15 | EventType.PERIGEE: (_("%s is at its perigee"), None), |
22 | 16 | EventType.APOGEE: (_("%s is at its apogee"), None), |
23 | | - }.get(event.event_type) |
| 17 | + }.get(event.event_type, (None, None)) |
24 | 18 |
|
25 | 19 | if string is None: |
26 | 20 | return None |
27 | 21 |
|
28 | 22 | string = string % tuple([from_object(o.identifier) for o in event.objects]) |
29 | 23 |
|
30 | 24 | if details is not None and with_description: |
31 | | - return "%s (%s)" % (string, details) |
| 25 | + return "%s (%s)" % (string, details()) |
32 | 26 |
|
33 | 27 | return string |
34 | 28 |
|
|
0 commit comments