import json, sys
from datetime import datetime, timedelta
# Export only reviewed rows from the applicable official class-specific table.
policy = json.load(open(sys.argv[1], encoding="utf-8"))
for row in json.load(open(sys.argv[2], encoding="utf-8")):
    key = ":".join((row["certificationClass"], str(row["currentRating"]),
        "LEV" if row["isLikelyExploitable"] else "NLEV",
        "IRV" if row["isInternetReachable"] else "NIRV"))
    if key not in policy["reviewedHours"]:
        raise ValueError("No reviewed timeframe: " + key)
    start = datetime.fromisoformat(row["evaluatedAt"].replace("Z", "+00:00"))
    due = start + timedelta(hours=policy["reviewedHours"][key])
    print(json.dumps({"id": row["id"], "candidateDueAt": due.isoformat(),
        "policyVersion": policy["version"], "kevReviewRequired": True}))
