37 lines
879 B
Python
37 lines
879 B
Python
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 3:
|
|
print("usage: edge_local_sync.py <edge_url> <payload_json_path>")
|
|
return 2
|
|
|
|
edge_url = sys.argv[1].rstrip("/") + "/debug/sync"
|
|
payload_path = sys.argv[2]
|
|
|
|
with open(payload_path, "r", encoding="utf-8") as f:
|
|
payload = f.read()
|
|
|
|
data = payload.encode("utf-8")
|
|
req = urllib.request.Request(
|
|
edge_url,
|
|
data=data,
|
|
headers={"Content-Type": "application/json"},
|
|
method="POST",
|
|
)
|
|
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
body = resp.read().decode("utf-8", errors="ignore")
|
|
print(body)
|
|
return 0 if resp.status == 200 else 1
|
|
except Exception as e:
|
|
print(f"error: {e}")
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|