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.
 
 
 
 

60 lines
2.1 KiB

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