Skip to content

Commit

Permalink
feat(ci): check users and eligibility also
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Dec 20, 2024
1 parent 231d3f0 commit 5d8051c
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/check-metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timezone
from functools import cache
import json
from pathlib import Path
import sys
Expand All @@ -15,19 +16,39 @@ def get_agency_url(agency: str):
return config[agency]


def check_metadata_timestamp(url):
now = datetime.now(tz=timezone.utc)
@cache
def get_metadata(url: str):
response = requests.get(url, timeout=30)
response.raise_for_status()
return response.json()


data = response.json()
def check_metadata_timestamp(url: str):
now = datetime.now(tz=timezone.utc)
data = get_metadata(url)
ts = data["db"]["timestamp"]
timestamp = datetime.fromisoformat(ts)

if not all((timestamp.year == now.year, timestamp.month == now.month, timestamp.day == now.day)):
raise RuntimeError(f"Database timestamp mismatch: {ts}")


def check_metadata_users(url: str):
data = get_metadata(url)
users = data["db"]["users"]

if users < 1:
raise RuntimeError("Database has no users")


def check_metadata_eligibility(url: str):
data = get_metadata(url)
eligibility = data["db"]["eligibility"]

if len(eligibility) < 1:
raise RuntimeError("Database has no eligibility")


if __name__ == "__main__":
args = sys.argv
if len(args) < 2:
Expand All @@ -36,3 +57,5 @@ def check_metadata_timestamp(url):
agency = args[1]
url = get_agency_url(agency)
check_metadata_timestamp(url)
check_metadata_users(url)
check_metadata_eligibility(url)

0 comments on commit 5d8051c

Please sign in to comment.