You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

64 lines
2.2 KiB

  1. #!/usr/bin/env python3
  2. from typing import Union
  3. from .utils import _
  4. from kosmorrolib import EventType, MoonPhaseType, ObjectIdentifier, Event
  5. def from_event(event: Event, with_description: bool = True) -> Union[None, str]:
  6. string, details = {
  7. EventType.OPPOSITION: (_("%s is in opposition"), None),
  8. EventType.CONJUNCTION: (_("%s and %s are in conjunction"), None),
  9. EventType.OCCULTATION: (_("%s occults %s"), None),
  10. EventType.MAXIMAL_ELONGATION: (
  11. _("Elongation of %s is maximal"),
  12. lambda e: "{:.3n}°".format(e.details["deg"]),
  13. ),
  14. EventType.PERIGEE: (_("%s is at its perigee"), None),
  15. EventType.APOGEE: (_("%s is at its apogee"), None),
  16. }.get(event.event_type, (None, None))
  17. if string is None:
  18. return None
  19. string = string % tuple([from_object(o.identifier) for o in event.objects])
  20. if details is not None and with_description:
  21. return "%s (%s)" % (string, details(event))
  22. return string
  23. def from_moon_phase(moon_phase: MoonPhaseType) -> str:
  24. string = {
  25. MoonPhaseType.NEW_MOON: _("New Moon"),
  26. MoonPhaseType.WAXING_CRESCENT: _("Waxing Crescent"),
  27. MoonPhaseType.FIRST_QUARTER: _("First Quarter"),
  28. MoonPhaseType.WAXING_GIBBOUS: _("Waxing Gibbous"),
  29. MoonPhaseType.FULL_MOON: _("Full Moon"),
  30. MoonPhaseType.WANING_GIBBOUS: _("Waning Gibbous"),
  31. MoonPhaseType.LAST_QUARTER: _("Last Quarter"),
  32. MoonPhaseType.WANING_CRESCENT: _("Waning Crescent"),
  33. }.get(moon_phase)
  34. if string is None:
  35. raise RuntimeError("Unknown moon phase: %s." % moon_phase)
  36. return string
  37. def from_object(identifier: ObjectIdentifier) -> str:
  38. return {
  39. ObjectIdentifier.SUN: _("Sun"),
  40. ObjectIdentifier.MOON: _("Moon"),
  41. ObjectIdentifier.MERCURY: _("Mercury"),
  42. ObjectIdentifier.VENUS: _("Venus"),
  43. ObjectIdentifier.MARS: _("Mars"),
  44. ObjectIdentifier.JUPITER: _("Jupiter"),
  45. ObjectIdentifier.SATURN: _("Saturn"),
  46. ObjectIdentifier.URANUS: _("Uranus"),
  47. ObjectIdentifier.NEPTUNE: _("Neptune"),
  48. ObjectIdentifier.PLUTO: _("Pluto"),
  49. }.get(identifier)