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

57 строки
2.3 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorro - Compute The Next Ephemeris
  3. # Copyright (C) 2019 Jérôme Deuchnord <jerome@deuchnord.fr>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. from abc import ABC, abstractmethod
  18. from tabulate import tabulate
  19. from skyfield import almanac
  20. class Dumper(ABC):
  21. def __init__(self, ephemeris):
  22. self.ephemeris = ephemeris
  23. @abstractmethod
  24. def to_string(self):
  25. pass
  26. class TextDumper(Dumper):
  27. def to_string(self):
  28. return '\n\n'.join([self.get_planets(self.ephemeris['planets'], self.ephemeris['sun']),
  29. self.get_moon(self.ephemeris['moon'])])
  30. @staticmethod
  31. def get_planets(planets, sun):
  32. data = [['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. data.append([name, planet_rise, planet_maximum, planet_set])
  41. return tabulate(data, 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']]