agenda/update_thespacedevs.py

27 lines
653 B
Python
Executable file

#!/usr/bin/python3
"""Update cache of space launch API."""
import asyncio
import os
import sys
from time import time
import agenda.thespacedevs
config = __import__("config.default", fromlist=[""])
rocket_dir = os.path.join(config.DATA_DIR, "thespacedevs")
async def get_launches() -> list[agenda.thespacedevs.Launch]:
"""Call space launch API and cache results."""
return await agenda.thespacedevs.get_launches(rocket_dir, limit=200, refresh=True)
t0 = time()
rockets = asyncio.run(get_launches())
time_taken = time() - t0
if not sys.stdin.isatty():
sys.exit(0)
print(len(rockets), "launches")
print(f"took {time_taken:.1f} seconds")