Example #1
0
    client = Client()
    client.connect(**config)

    # Create and send the request to the server
    message = []
    for operation in Client.OPERATIONS:
        if args[operation]:
            value = args[operation] if isinstance(args[operation], list) \
                    else [args[operation]]
            message.append([Client.OPERATIONS.index(operation), value])
    if not message:  # Show all tasks if no operation flags specified
        message.append([Client.OPERATIONS.index('show'), []])
    client.send(json.dumps(message))

    # Parse the response
    response = json.loads(client.receive())
    for action in response:
        operation_name = Client.OPERATIONS[action[0]]
        if action[1] == Database.SUCCESS:
            print '%s info: Success' %operation_name
        elif action[1] == Database.DUPLICATE:
            print '%s error: Duplicate entry.' %operation_name
        elif action[1] == Database.DOES_NOT_EXIST:
            print '%s error: Row does not exist.' %operation_name
        elif action[1] == Database.INVALID_ID:
            print '%s error: Invalid task ID.' %operation_name
        elif action[1] == Database.INVALID_DATE:
            print '%s error: Invalid date format.' %operation_name
        elif action[1] == Database.DATA:
            todo_print.print_tasks(action[2])
        else: