Exemplo n.º 1
0
def get_instructions():    
    if not request.query_string:        
        print 'Returning all instructions...'
        allInstructions = db_adapter.get_instructions(0,2147483648); #end of unix time
        response.content_type = 'application/json;'
        return json_parser.get_instruction_array_as_json(allInstructions)
    if (request.query_string is not None) & ('now' in request.query_string):
        print 'Returning instruction for current time...'
        try:
            return json_parser.get_instruction_as_json(db_adapter.get_instructions()[0])
        except IndexError:
            # no current instruction
            response.status = 204
            return ''
    start_timestamp, end_timestamp = _get_timestamp_query_parameters()
    try:
        print 'Asked for instructions from ' + misc_utils.timestamp_to_datetime(float(start_timestamp)).strftime("%c") + ' to ' + misc_utils.timestamp_to_datetime(float(end_timestamp)).strftime("%c") + '...',
        all_instructions = db_adapter.get_instructions(int(start_timestamp), int(end_timestamp))
        print 'got ' + str(len(all_instructions)) + ' result(s).'
        response.content_type = 'application/json;'                        
        return json_parser.get_instruction_array_as_json(all_instructions)    
    except (TypeError, ValueError) as e:
        abort(400, "Malformed timestamp parameter(s): " + str(e))
Exemplo n.º 2
0
def get_instruction(instruction_id):
    instruction = _get_instruction(instruction_id)
    return json_parser.get_instruction_as_json(instruction)