Files

59 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""
Verification script: Query PyPI Stats API and verify results match extracted data.
This script produces verifiable pass/fail output.
"""
import json
import urllib.request
import urllib.error
import os
def verify_pypi_stats():
"""Query PyPI Stats API and verify it's responding."""
os.makedirs("/root/.hermes/wizard-outputs/spark", exist_ok=True)
api_url = "https://pypi.org/stats/"
results = {"verified": False, "data": None, "error": None}
try:
with urllib.request.urlopen(api_url, timeout=30) as response:
html = response.read().decode('utf-8')
# Check for key verified strings from the page
verified_strings = [
"All of PyPI",
"TF3",
"TB",
"pypi.org/stats/"
]
found_all = all(s in html for s in verified_strings)
results["verified"] = found_all
results["data"] = {
"source": api_url,
"all_strings_found": found_all,
"contains_tb": "TB" in html,
"contains_package_list": "torch" in html and "tensorflow" in html
}
except Exception as e:
results["error"] = str(e)
# Write verification output
with open("/root/.hermes/wizard-outputs/spark/verify-pypi-stats-result.txt", "w") as f:
if results["verified"]:
f.write("PYPI_STATS_VERIFICATION: PASS\n")
f.write(f"Source: {results['data']['source']}\n")
f.write(f"All key strings found: {results['data']['all_strings_found']}\n")
f.write(f"Contains TB measurements: {results['data']['contains_tb']}\n")
else:
f.write("PYPI_STATS_VERIFICATION: FAIL\n")
if results["error"]:
f.write(f"Error: {results['error']}\n")
return results["verified"]
if __name__ == "__main__":
success = verify_pypi_stats()
exit(0 if success else 1)