Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

67 linhas
2.2 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: (
  10. _("Elongation of %s is maximal"),
  11. (
  12. "{:.3n}°".format(event.details["deg"])
  13. if type(event.details) is dict
  14. else event.details
  15. ),
  16. ),
  17. EventType.MOON_PERIGEE: (_("%s is at its perigee"), None),
  18. EventType.MOON_APOGEE: (_("%s is at its apogee"), None),
  19. }.get(event.event_type)
  20. if string is None:
  21. return None
  22. string = string % tuple([from_object(o.identifier) for o in event.objects])
  23. if details is not None and with_description:
  24. return "%s (%s)" % (string, details)
  25. return string
  26. def from_moon_phase(moon_phase: MoonPhaseType) -> str:
  27. string = {
  28. MoonPhaseType.NEW_MOON: _("New Moon"),
  29. MoonPhaseType.WAXING_CRESCENT: _("Waxing Crescent"),
  30. MoonPhaseType.FIRST_QUARTER: _("First Quarter"),
  31. MoonPhaseType.WAXING_GIBBOUS: _("Waxing Gibbous"),
  32. MoonPhaseType.FULL_MOON: _("Full Moon"),
  33. MoonPhaseType.WANING_GIBBOUS: _("Waning Gibbous"),
  34. MoonPhaseType.LAST_QUARTER: _("Last Quarter"),
  35. MoonPhaseType.WANING_CRESCENT: _("Waning Crescent"),
  36. }.get(moon_phase)
  37. if string is None:
  38. raise RuntimeError("Unknown moon phase: %s." % moon_phase)
  39. return string
  40. def from_object(identifier: ObjectIdentifier) -> str:
  41. return {
  42. ObjectIdentifier.SUN: _("Sun"),
  43. ObjectIdentifier.MOON: _("Moon"),
  44. ObjectIdentifier.MERCURY: _("Mercury"),
  45. ObjectIdentifier.VENUS: _("Venus"),
  46. ObjectIdentifier.MARS: _("Mars"),
  47. ObjectIdentifier.JUPITER: _("Jupiter"),
  48. ObjectIdentifier.SATURN: _("Saturn"),
  49. ObjectIdentifier.URANUS: _("Uranus"),
  50. ObjectIdentifier.NEPTUNE: _("Neptune"),
  51. ObjectIdentifier.PLUTO: _("Pluto"),
  52. }.get(identifier)