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.
 
 
 
 

73 lines
2.6 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorro - Compute The Next Ephemerides
  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. import datetime
  19. from tabulate import tabulate
  20. from skyfield import almanac
  21. from .data import Object
  22. class Dumper(ABC):
  23. def __init__(self, ephemeris, date: datetime.date = datetime.date.today()):
  24. self.ephemeris = ephemeris
  25. self.date = date
  26. @abstractmethod
  27. def to_string(self):
  28. pass
  29. class TextDumper(Dumper):
  30. def to_string(self):
  31. return '\n\n'.join(['Ephemerides of %s' % self.date.strftime('%A %B %d, %Y'),
  32. self.get_asters(self.ephemeris['planets']),
  33. self.get_moon(self.ephemeris['moon_phase']),
  34. 'Note: All the hours are given in UTC.'])
  35. @staticmethod
  36. def get_asters(asters: [Object]) -> str:
  37. data = []
  38. for aster in asters:
  39. name = aster.name
  40. if aster.ephemerides.rise_time is not None:
  41. planet_rise = aster.ephemerides.rise_time.utc_strftime('%H:%M')
  42. else:
  43. planet_rise = '-'
  44. if aster.ephemerides.maximum_time is not None:
  45. planet_maximum = aster.ephemerides.maximum_time.utc_strftime('%H:%M')
  46. else:
  47. planet_maximum = '-'
  48. if aster.ephemerides.set_time is not None:
  49. planet_set = aster.ephemerides.set_time.utc_strftime('%H:%M')
  50. else:
  51. planet_set = '-'
  52. data.append([name, planet_rise, planet_maximum, planet_set])
  53. return tabulate(data, headers=['Planet', 'Rise time', 'Culmination time', 'Set time'], tablefmt='simple',
  54. stralign='center', colalign=('left',))
  55. @staticmethod
  56. def get_moon(moon):
  57. return 'Moon phase: %s' % almanac.MOON_PHASES[moon['phase']]