intake/tests/demo_basic_callback/increment.py

26 lines
562 B
Python
Raw Normal View History

2023-06-01 03:50:56 +00:00
#!/usr/bin/env python3
import argparse, json, sys
parser = argparse.ArgumentParser()
parser.add_argument("action")
args = parser.parse_args()
print("args:", args, file=sys.stderr, flush=True)
if args.action == "fetch":
print(json.dumps({
"id": "updateme",
"action": {
"increment": 1
}
}))
2023-06-01 03:50:56 +00:00
if args.action == "increment":
item = sys.stdin.readline()
item = json.loads(item)
item["action"]["increment"] += 1
2023-06-02 00:03:30 +00:00
item["body"] = f"<p>{item['action']['increment']}</p>"
2023-06-01 03:50:56 +00:00
print(json.dumps(item))
pass