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":
|
2023-06-04 22:31:08 +00:00
|
|
|
print(
|
|
|
|
json.dumps(
|
|
|
|
{
|
|
|
|
"id": "updateme",
|
|
|
|
"title": "The count is at 1",
|
|
|
|
"action": {
|
|
|
|
"increment": 1,
|
|
|
|
"decrement": "",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2023-06-01 03:50:56 +00:00
|
|
|
|
|
|
|
if args.action == "increment":
|
|
|
|
item = sys.stdin.readline()
|
|
|
|
item = json.loads(item)
|
2023-06-01 23:41:50 +00:00
|
|
|
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))
|