BREAKING CHANGE: invoking kosmorro command without --latitude and --longitude arguments will now only output the Moon phase and, eventually, the events for the given date (or today if date not given).tags/v0.4.0
| @@ -43,7 +43,12 @@ def main(): | |||||
| if day is not None and month is None: | if day is not None and month is None: | ||||
| month = date.today().month | month = date.today().month | ||||
| ephemeris = EphemeridesComputer(Position(args.latitude, args.longitude)) | |||||
| if args.latitude is None or args.longitude is None: | |||||
| position = None | |||||
| else: | |||||
| position = Position(args.latitude, args.longitude) | |||||
| ephemeris = EphemeridesComputer(position) | |||||
| ephemerides = ephemeris.compute_ephemerides(year, month, day) | ephemerides = ephemeris.compute_ephemerides(year, month, day) | ||||
| events_list = events.search_events(compute_date) | events_list = events.search_events(compute_date) | ||||
| @@ -86,10 +91,11 @@ def clear_cache() -> bool: | |||||
| def get_args(output_formats: [str]): | def get_args(output_formats: [str]): | ||||
| today = date.today() | today = date.today() | ||||
| parser = argparse.ArgumentParser(description='Compute the ephemerides for a given date, at a given position' | |||||
| ' on Earth.', | |||||
| epilog='By default, the ephemerides will be computed for today (%s) for an' | |||||
| ' observer positioned at coordinates (0,0).' | |||||
| parser = argparse.ArgumentParser(description='Compute the ephemerides and the events for a given date,' | |||||
| ' at a given position on Earth.', | |||||
| epilog='By default, only the events will be computed for today (%s).\n' | |||||
| 'To compute also the ephemerides, latitude and longitude arguments' | |||||
| ' are needed.' | |||||
| % today.strftime('%a %b %d, %Y')) | % today.strftime('%a %b %d, %Y')) | ||||
| parser.add_argument('--version', '-v', dest='special_action', action='store_const', const=output_version, | parser.add_argument('--version', '-v', dest='special_action', action='store_const', const=output_version, | ||||
| @@ -98,9 +104,9 @@ def get_args(output_formats: [str]): | |||||
| help='Delete all the files Kosmorro stored in the cache.') | help='Delete all the files Kosmorro stored in the cache.') | ||||
| parser.add_argument('--format', '-f', type=str, default=output_formats[0], choices=output_formats, | parser.add_argument('--format', '-f', type=str, default=output_formats[0], choices=output_formats, | ||||
| help='The format under which the information have to be output') | help='The format under which the information have to be output') | ||||
| parser.add_argument('--latitude', '-lat', type=float, default=0., | |||||
| parser.add_argument('--latitude', '-lat', type=float, default=None, | |||||
| help="The observer's latitude on Earth") | help="The observer's latitude on Earth") | ||||
| parser.add_argument('--longitude', '-lon', type=float, default=0., | |||||
| parser.add_argument('--longitude', '-lon', type=float, default=None, | |||||
| help="The observer's longitude on Earth") | help="The observer's longitude on Earth") | ||||
| parser.add_argument('--day', '-d', type=int, default=today.day, | parser.add_argument('--day', '-d', type=int, default=today.day, | ||||
| help='A number between 1 and 28, 29, 30 or 31 (depending on the month). The day you want to ' | help='A number between 1 and 28, 29, 30 or 31 (depending on the month). The day you want to ' | ||||
| @@ -72,9 +72,14 @@ class JsonDumper(Dumper): | |||||
| class TextDumper(Dumper): | class TextDumper(Dumper): | ||||
| def to_string(self): | def to_string(self): | ||||
| text = 'Ephemerides of %s' % self.date.strftime('%A %B %d, %Y') | |||||
| text = self.date.strftime('%A %B %d, %Y') | |||||
| if len(self.ephemeris['details']) > 0: | |||||
| text = '\n\n'.join([text, | |||||
| self.get_asters(self.ephemeris['details']) | |||||
| ]) | |||||
| text = '\n\n'.join([text, | text = '\n\n'.join([text, | ||||
| self.get_asters(self.ephemeris['details']), | |||||
| self.get_moon(self.ephemeris['moon_phase']) | self.get_moon(self.ephemeris['moon_phase']) | ||||
| ]) | ]) | ||||
| @@ -17,6 +17,7 @@ | |||||
| # along with this program. If not, see <https://www.gnu.org/licenses/>. | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
| import datetime | import datetime | ||||
| from typing import Union | |||||
| from skyfield import almanac | from skyfield import almanac | ||||
| from skyfield.timelib import Time | from skyfield.timelib import Time | ||||
| @@ -29,8 +30,9 @@ RISEN_ANGLE = -0.8333 | |||||
| class EphemeridesComputer: | class EphemeridesComputer: | ||||
| def __init__(self, position: Position): | |||||
| position.observation_planet = get_skf_objects()['earth'] | |||||
| def __init__(self, position: Union[Position, None]): | |||||
| if position is not None: | |||||
| position.observation_planet = get_skf_objects()['earth'] | |||||
| self.position = position | self.position = position | ||||
| def get_sun(self, start_time, end_time) -> dict: | def get_sun(self, start_time, end_time) -> dict: | ||||
| @@ -107,7 +109,7 @@ class EphemeridesComputer: | |||||
| def compute_ephemerides_for_day(self, year: int, month: int, day: int) -> dict: | def compute_ephemerides_for_day(self, year: int, month: int, day: int) -> dict: | ||||
| return {'moon_phase': self.get_moon_phase(year, month, day), | return {'moon_phase': self.get_moon_phase(year, month, day), | ||||
| 'details': [self.get_asters_ephemerides_for_aster(aster, datetime.date(year, month, day), self.position) | 'details': [self.get_asters_ephemerides_for_aster(aster, datetime.date(year, month, day), self.position) | ||||
| for aster in ASTERS]} | |||||
| for aster in ASTERS] if self.position is not None else []} | |||||
| def compute_ephemerides_for_month(self, year: int, month: int) -> [dict]: | def compute_ephemerides_for_month(self, year: int, month: int) -> [dict]: | ||||
| if month == 2: | if month == 2: | ||||
| @@ -43,7 +43,7 @@ class DumperTestCase(unittest.TestCase): | |||||
| def test_text_dumper_without_events(self): | def test_text_dumper_without_events(self): | ||||
| ephemerides = self._get_data() | ephemerides = self._get_data() | ||||
| self.assertEqual('Ephemerides of Monday October 14, 2019\n\n' | |||||
| self.assertEqual('Monday October 14, 2019\n\n' | |||||
| 'Object Rise time Culmination time Set time\n' | 'Object Rise time Culmination time Set time\n' | ||||
| '-------- ----------- ------------------ ----------\n' | '-------- ----------- ------------------ ----------\n' | ||||
| 'Mars - - -\n\n' | 'Mars - - -\n\n' | ||||
| @@ -54,7 +54,7 @@ class DumperTestCase(unittest.TestCase): | |||||
| def test_text_dumper_with_events(self): | def test_text_dumper_with_events(self): | ||||
| ephemerides = self._get_data() | ephemerides = self._get_data() | ||||
| self.assertEqual('Ephemerides of Monday October 14, 2019\n\n' | |||||
| self.assertEqual('Monday October 14, 2019\n\n' | |||||
| 'Object Rise time Culmination time Set time\n' | 'Object Rise time Culmination time Set time\n' | ||||
| '-------- ----------- ------------------ ----------\n' | '-------- ----------- ------------------ ----------\n' | ||||
| 'Mars - - -\n\n' | 'Mars - - -\n\n' | ||||
| @@ -68,11 +68,24 @@ class DumperTestCase(unittest.TestCase): | |||||
| get_timescale().utc(2018, 7, 27, 5, 12)) | get_timescale().utc(2018, 7, 27, 5, 12)) | ||||
| ], date=date(2019, 10, 14)).to_string()) | ], date=date(2019, 10, 14)).to_string()) | ||||
| def test_text_dumper_without_ephemerides_and_with_events(self): | |||||
| ephemerides = self._get_data(False) | |||||
| self.assertEqual('Monday October 14, 2019\n\n' | |||||
| 'Moon phase: Full Moon\n' | |||||
| 'Last Quarter on Mon Oct 21, 2019 00:00\n\n' | |||||
| 'Expected events:\n\n' | |||||
| '05:12 Mars is in opposition\n\n' | |||||
| 'Note: All the hours are given in UTC.', | |||||
| TextDumper(ephemerides, [Event('OPPOSITION', | |||||
| Planet('Mars', 'MARS'), | |||||
| get_timescale().utc(2018, 7, 27, 5, 12)) | |||||
| ], date=date(2019, 10, 14)).to_string()) | |||||
| @staticmethod | @staticmethod | ||||
| def _get_data(): | |||||
| def _get_data(has_ephemerides: bool = True): | |||||
| return { | return { | ||||
| 'moon_phase': MoonPhase('FULL_MOON', get_timescale().utc(2019, 10, 14), get_timescale().utc(2019, 10, 21)), | 'moon_phase': MoonPhase('FULL_MOON', get_timescale().utc(2019, 10, 14), get_timescale().utc(2019, 10, 21)), | ||||
| 'details': [Planet('Mars', 'MARS', AsterEphemerides(None, None, None))] | |||||
| 'details': [Planet('Mars', 'MARS', AsterEphemerides(None, None, None))] if has_ephemerides else [] | |||||
| } | } | ||||