57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Verifiable script: Query a public API and produce concrete output.
|
|
Uses urllib to query a real API with verifiable response.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import urllib.request
|
|
import urllib.error
|
|
|
|
# Create output directory
|
|
os.makedirs("/root/.hermes/wizard-outputs/spark", exist_ok=True)
|
|
|
|
# Query a verifiable public API - PyPI's simple API returns predictable JSON
|
|
api_url = "https://pypi.org/pypi/json"
|
|
|
|
try:
|
|
with urllib.request.urlopen(api_url, timeout=30) as response:
|
|
data = json.loads(response.read().decode('utf-8'))
|
|
|
|
# Extract concrete, verifiable data
|
|
package_count = len(data.get("releases", {}))
|
|
|
|
output_lines = [
|
|
"PYPI API VERIFICATION OUTPUT",
|
|
"=" * 50,
|
|
f"Source: {api_url}",
|
|
f"Total packages in database: {package_count}",
|
|
f"Package names (first 10):",
|
|
]
|
|
|
|
pkg_names = list(data.get("releases", {}).keys())[:10]
|
|
for i, name in enumerate(pkg_names, 1):
|
|
info = data["releases"][name][0] if data["releases"][name] else {}
|
|
version = info.get("version", "N/A")
|
|
output_lines.append(f" {i}. {name} (v{version})")
|
|
|
|
output_text = "\n".join(output_lines)
|
|
|
|
with open("/root/.hermes/wizard-outputs/spark/pypi-verify-output.txt", "w") as f:
|
|
f.write(output_text + "\n")
|
|
|
|
# Write verification marker
|
|
with open("/root/.hermes/wizard-outputs/spark/pypi-verify-marker.txt", "w") as f:
|
|
f.write(f"packages_count:{package_count}\nverified:True\n")
|
|
|
|
print(f"VERIFIED: Found {package_count} packages on PyPI")
|
|
|
|
except urllib.error.URLError as e:
|
|
with open("/root/.hermes/wizard-outputs/spark/pypi-verify-output.txt", "w") as f:
|
|
f.write(f"ERROR: Could not reach PyPI API: {e}\n")
|
|
print(f"ERROR: {e}")
|
|
except Exception as e:
|
|
with open("/root/.hermes/wizard-outputs/spark/pypi-verify-output.txt", "w") as f:
|
|
f.write(f"ERROR: {e}\n")
|
|
print(f"ERROR: {e}") |