#!/usr/bin/env python3 import argparse, json, sys, time parser = argparse.ArgumentParser() parser.add_argument("action") args = parser.parse_args() print("args:", args, file=sys.stderr, flush=True) def item(i): print(json.dumps(i)) if args.action == "fetch": item({ "id": "item1-only-id", }) item({ "id": "item2-title", "title": "This item has a title", }) item({ "id": "item3-body", "title": "This item has a title and body", "body": "
Hello, intake! This is an item body.
", }) item({ "id": "item4-action", "title": "This item has an action but no body", "action": { "action1": None }, }) item({ "id": "item5-actions", "title": "This item has two actions and a body", "body": "This is body text.
", "action": { "action1": None, "action2": None, }, }) item({ "id": "item6-footer", "title": "No body text but all footer fields", "author": "Authorname", "time": int(time.time()), }) item({ "id": "item7-footer", "title": "Body text and all footer fields", "author": "Authorname", "time": int(time.time()), "body": "This is body text.
", }) item({ "id": "item8-link", "title": "Item with a link", "link": "#", }) if args.action == "action1": item = sys.stdin.readline() item = json.loads(item) print(json.dumps(item)) if args.action == "action2": item = sys.stdin.readline() item = json.loads(item) print(json.dumps(item))