Пример #1
0
    args = parser.parse_args()

    task_manager = None
    state_manager = StateManager()

    if args.dev:
        logging.basicConfig(level=logging.DEBUG)

    # noinspection PyBroadException
    try:
        if args.action == action_get:
            if args.state_id:
                state = state_manager.get_state(args.state_id)
            else:
                state = state_manager.get_latest_state(args.file_path)

            context = json.loads(args.context) if args.context else None
            task_manager = TaskManager()
            tasks = task_manager.get_suggested_tasks(state, context)
            print(json.dumps(tasks))
            task_manager.close_db()

        elif args.action == action_execute:
            task_manager = TaskManager()
            new_state = task_manager.execute_task(args.task_id)
            state_manager.add_state(new_state)

            print(
                json.dumps(state_manager.jsonify(new_state),
                           indent=(3 if args.dev else None)))
Пример #2
0
        "sheet_name", help="Name of the sheet", type=str, default="default"
    )

    action_load = "load"
    load_parser = subparsers.add_parser(action_load)
    load_parser.add_argument(
        "state_id", help="The id of the state to be loaded", type=int
    )

    args = parser.parse_args()
    manager = StateManager()

    # noinspection PyBroadException
    try:
        if args.action == action_initialize:
            state = manager.get_latest_state(args.file_path, args.sheet_name)

            if state is None:
                state = manager.create_empty_state(args.file_path, args.sheet_name)
                manager.add_state(state)
                assert state is not None

            manager.print_state(state)

        elif args.action == action_load:
            state = manager.get_state(args.state_id)
            manager.set_latest(state)
            manager.print_state(state)

    except Exception as e:
        print(json.dumps({"exception": traceback.format_exc()}))