intake/tests/demo_basic_callback/increment.py

36 lines
975 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",
2023-06-02 23:57:03 +00:00
"title": "The count is at 1",
"action": {
2023-06-03 00:09:51 +00:00
"increment": 1,
"decrement": "",
}
}))
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-02 23:57:03 +00:00
item["title"] = f"The count is at {item['action']['increment']}"
2023-06-01 03:50:56 +00:00
print(json.dumps(item))
2023-06-03 00:09:51 +00:00
if args.action == "decrement":
item = sys.stdin.readline()
item = json.loads(item)
item["action"]["increment"] -= 1
item["body"] = f"<p>{item['action']['increment']}</p>"
item["title"] = f"The count is at {item['action']['increment']}"
print(json.dumps(item))