Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

56 строки
2.2 KiB

  1. # Kosmorro - Compute The Next Ephemeris
  2. # Copyright (C) 2019 Jérôme Deuchnord <jerome@deuchnord.fr>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from abc import ABC, abstractmethod
  17. from tabulate import tabulate
  18. from skyfield import almanac
  19. class Dumper(ABC):
  20. def __init__(self, ephemeris):
  21. self.ephemeris = ephemeris
  22. @abstractmethod
  23. def to_string(self):
  24. pass
  25. class TextDumper(Dumper):
  26. def to_string(self):
  27. s = '\n\n'.join([self.get_planets(self.ephemeris['planets'], self.ephemeris['sun']),
  28. self.get_moon(self.ephemeris['moon'])])
  29. return s
  30. @staticmethod
  31. def get_planets(planets, sun):
  32. s = [['SUN', sun['rise'].utc_strftime('%H:%M'), '-', sun['set'].utc_strftime('%H:%M')]]
  33. for planet in planets:
  34. name = planet
  35. planet_data = planets[planet]
  36. planet_rise = planet_data['rise'].utc_strftime('%H:%M') if planet_data['rise'] is not None else ' -'
  37. planet_maximum = planet_data['maximum'].utc_strftime('%H:%M') if planet_data['maximum'] is not None\
  38. else ' -'
  39. planet_set = planet_data['set'].utc_strftime('%H:%M') if planet_data['set'] is not None else ' -'
  40. s.append([name, planet_rise, planet_maximum, planet_set])
  41. return tabulate(s, headers=['Planet', 'Rise time', 'Maximum time', 'Set time'], tablefmt='simple',
  42. stralign='center', colalign=('left',))
  43. @staticmethod
  44. def get_moon(moon):
  45. return 'Moon phase: %s' % almanac.MOON_PHASES[moon['phase']]