您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

80 行
3.4 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. import numpy
  20. from kosmorrolib import dumper
  21. from kosmorrolib.ephemerides import EphemeridesComputer, Position
  22. # Fixes the "TypeError: Object of type int64 is not JSON serializable"
  23. # See https://stackoverflow.com/a/50577730
  24. def json_default(obj):
  25. if isinstance(obj, numpy.int64):
  26. return int(obj)
  27. raise TypeError('Object of type ' + str(type(obj)) + ' could not be integrated in the JSON')
  28. def main():
  29. args = get_args()
  30. year = args.year
  31. month = args.month
  32. day = args.day
  33. if day is not None and month is None:
  34. month = date.today().month
  35. ephemeris = EphemeridesComputer(Position(args.latitude, args.longitude, altitude=args.altitude))
  36. ephemerides = ephemeris.compute_ephemerides(year, month, day)
  37. dump = dumper.TextDumper(ephemerides)
  38. print(dump.to_string())
  39. def get_args():
  40. today = date.today()
  41. parser = argparse.ArgumentParser(description='Compute the ephemerides for a given date, at a given position'
  42. ' on Earth.',
  43. epilog='By default, the ephemerides will be computed for today (%s) for an'
  44. ' observer positioned at coordinates (0,0), with an altitude of 0.'
  45. % today.strftime('%a %b %d, %Y'))
  46. parser.add_argument('--latitude', '-lat', type=float, default=0.,
  47. help="The observer's latitude on Earth")
  48. parser.add_argument('--longitude', '-lon', type=float, default=0.,
  49. help="The observer's longitude on Earth")
  50. parser.add_argument('--altitude', '-alt', type=float, default=0.,
  51. help="The observer's altitude on Earth")
  52. parser.add_argument('--day', '-d', type=int, default=today.day,
  53. help='A number between 1 and 28, 29, 30 or 31 (depending on the month). The day you want to '
  54. ' compute the ephemerides for. Defaults to %d (the current day).' % today.day)
  55. parser.add_argument('--month', '-m', type=int, default=today.month,
  56. help='A number between 1 and 12. The month you want to compute the ephemerides for. Defaults to'
  57. ' %d (the current month).' % today.month)
  58. parser.add_argument('--year', '-y', type=int, default=today.year,
  59. help='The year you want to compute the ephemerides for.'
  60. ' Defaults to %d (the current year).' % today.year)
  61. return parser.parse_args()
  62. if __name__ == '__main__':
  63. main()