From f30c66fa07e8a30d9927b388396cf4161b6f9cc5 Mon Sep 17 00:00:00 2001 From: Deuchnord Date: Thu, 7 May 2026 10:09:37 +0200 Subject: [PATCH] chore: refactor --- .gitpod.yml | 12 ----- kosmorrolib/ephemerides.py | 89 +++++++++++++++++++------------------- 2 files changed, 45 insertions(+), 56 deletions(-) delete mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index d711b96..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,12 +0,0 @@ -github: - prebuilds: - pullRequestsFromForks: true - -vscode: - extensions: - - ms-vscode.makefile-tools - - editorconfig.editorconfig - -tasks: - - before: pip install -U pip poetry - init: poetry install diff --git a/kosmorrolib/ephemerides.py b/kosmorrolib/ephemerides.py index 88a7ed9..ee44939 100644 --- a/kosmorrolib/ephemerides.py +++ b/kosmorrolib/ephemerides.py @@ -30,7 +30,6 @@ from .core import ( get_skf_objects, get_timescale, get_iau2000b, - deprecated, alert_deprecation, ) from .enum import MoonPhaseType @@ -39,48 +38,6 @@ from .exceptions import OutOfRangeDateError RISEN_ANGLE = -0.8333 -def _get_skyfield_to_moon_phase( - times: [Time], vals: [int], now: Time, utc_offset: Union[int, float] -) -> Union[MoonPhase, None]: - tomorrow = get_timescale().utc( - now.utc_datetime().year, now.utc_datetime().month, now.utc_datetime().day + 1 - ) - - next_phase_time = None - i = 0 - - # Find the current moon phase: - for i, time in enumerate(times): - if now.utc_datetime() <= time.utc_datetime(): - if time.utc_datetime() >= tomorrow.utc_datetime(): - i -= 1 - break - - current_phase = MoonPhaseType(vals[i]) - - if current_phase in [ - MoonPhaseType.NEW_MOON, - MoonPhaseType.FIRST_QUARTER, - MoonPhaseType.FULL_MOON, - MoonPhaseType.LAST_QUARTER, - ]: - current_phase_time = translate_to_utc_offset( - times[i].utc_datetime(), utc_offset - ) - else: - current_phase_time = None - - # Find the next moon phase - for j in range(i + 1, len(times)): - if vals[j] in [0, 2, 4, 6]: - next_phase_time = translate_to_utc_offset( - times[j].utc_datetime(), utc_offset - ) - break - - return MoonPhase(current_phase, current_phase_time, next_phase_time) - - def get_moon_phase( for_date: date = date.today(), utc_offset: Union[int, float] = 0, **argv ) -> MoonPhase: @@ -116,6 +73,49 @@ def get_moon_phase( kosmorrolib.exceptions.OutOfRangeDateError: The date must be between 1899-08-09 and 2053-09-26 """ + def _get_skyfield_to_moon_phase( + times: [Time], vals: [int], now: Time, utc_offset: Union[int, float] + ): + tomorrow = get_timescale().utc( + now.utc_datetime().year, + now.utc_datetime().month, + now.utc_datetime().day + 1, + ) + + next_phase_time = None + i = 0 + + # Find the current moon phase: + for i, time in enumerate(times): + if now.utc_datetime() <= time.utc_datetime(): + if time.utc_datetime() >= tomorrow.utc_datetime(): + i -= 1 + break + + current_phase = MoonPhaseType(vals[i]) + + if current_phase in [ + MoonPhaseType.NEW_MOON, + MoonPhaseType.FIRST_QUARTER, + MoonPhaseType.FULL_MOON, + MoonPhaseType.LAST_QUARTER, + ]: + current_phase_time = translate_to_utc_offset( + times[i].utc_datetime(), utc_offset + ) + else: + current_phase_time = None + + # Find the next moon phase + for j in range(i + 1, len(times)): + if vals[j] in [0, 2, 4, 6]: + next_phase_time = translate_to_utc_offset( + times[j].utc_datetime(), utc_offset + ) + break + + return MoonPhase(current_phase, current_phase_time, next_phase_time) + if argv.get("timezone") is not None: alert_deprecation( "'timezone' argument of the get_moon_phase() function is deprecated. Use utc_offset instead." @@ -275,7 +275,8 @@ def get_ephemerides( alert_deprecation( "'timezone' argument of the get_ephemerides() function is deprecated. Use utc_offset instead." ) - utc_offset = argv.get("timezone") + + return get_ephemerides(position, for_date, argv.get("timezone")) def get_angle(for_aster: Object): def fun(time: Time) -> float: