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.
 
 
 
 

81 lines
3.5 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. import argparse
  18. from datetime import date
  19. from kosmorrolib import dumper
  20. from kosmorrolib.ephemerides import EphemeridesComputer, Position
  21. def main():
  22. output_formats = get_dumpers()
  23. args = get_args(list(output_formats.keys()))
  24. year = args.year
  25. month = args.month
  26. day = args.day
  27. if day is not None and month is None:
  28. month = date.today().month
  29. ephemeris = EphemeridesComputer(Position(args.latitude, args.longitude, altitude=args.altitude))
  30. ephemerides = ephemeris.compute_ephemerides(year, month, day)
  31. dump = output_formats[args.format](ephemerides)
  32. print(dump.to_string())
  33. def get_dumpers() -> {str: dumper.Dumper}:
  34. return {
  35. 'text': dumper.TextDumper,
  36. 'json': dumper.JsonDumper
  37. }
  38. def get_args(output_formats: [str]):
  39. today = date.today()
  40. parser = argparse.ArgumentParser(description='Compute the ephemerides for a given date, at a given position'
  41. ' on Earth.',
  42. epilog='By default, the ephemerides will be computed for today (%s) for an'
  43. ' observer positioned at coordinates (0,0), with an altitude of 0.'
  44. % today.strftime('%a %b %d, %Y'))
  45. parser.add_argument('--format', '-f', type=str, default=output_formats[0], choices=output_formats,
  46. help='The format under which the information have to be output')
  47. parser.add_argument('--latitude', '-lat', type=float, default=0.,
  48. help="The observer's latitude on Earth")
  49. parser.add_argument('--longitude', '-lon', type=float, default=0.,
  50. help="The observer's longitude on Earth")
  51. parser.add_argument('--altitude', '-alt', type=float, default=0.,
  52. help="The observer's altitude on Earth")
  53. parser.add_argument('--day', '-d', type=int, default=today.day,
  54. help='A number between 1 and 28, 29, 30 or 31 (depending on the month). The day you want to '
  55. ' compute the ephemerides for. Defaults to %d (the current day).' % today.day)
  56. parser.add_argument('--month', '-m', type=int, default=today.month,
  57. help='A number between 1 and 12. The month you want to compute the ephemerides for. Defaults to'
  58. ' %d (the current month).' % today.month)
  59. parser.add_argument('--year', '-y', type=int, default=today.year,
  60. help='The year you want to compute the ephemerides for.'
  61. ' Defaults to %d (the current year).' % today.year)
  62. return parser.parse_args()
  63. if __name__ == '__main__':
  64. main()