Skip to content

Commit

Permalink
Add command to print info about data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Jul 18, 2024
1 parent 30ee684 commit ddd9a0e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion leapseconddata/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import click

from . import LeapSecondData, tai
from . import InvalidHashError, LeapSecondData, tai

utc = datetime.timezone.utc

Expand Down Expand Up @@ -165,5 +165,29 @@ def table(ctx: click.Context, *, start: datetime.datetime, end: datetime.datetim
print(f"{leap_second.start:%Y-%m-%d}: {leap_second.tai_offset.total_seconds():.0f}")


@cli.command
def sources() -> None:
"""Print information about leap-second.list data sources"""
first = False
for location in LeapSecondData.standard_file_sources + LeapSecondData.standard_network_sources:
if not first:
print()
first = False
try:
leap_second_data = LeapSecondData.from_url(location, check_hash=True)
except InvalidHashError:
print(f"{location}: Invalid hash")
leap_second_data = LeapSecondData.from_url(location, check_hash=False)
except Exception as e: # noqa: BLE001
print(f"{location}: {e}")
leap_second_data = None

if leap_second_data is not None:
print(f"{location}: Last updated {leap_second_data.last_updated}")
print(f"{location}: Valid until {leap_second_data.valid_until}")
else:
print(f"{location}: Could not be read")


if __name__ == "__main__": # pragma no cover
cli()

0 comments on commit ddd9a0e

Please sign in to comment.