Ejemplo n.º 1
0
def runner_api(message):
    message = message.split(" ")
    stop_id = message[0]
    all_data = parse(stop_id)
    all_data = decode_api(all_data)

    return all_data
Ejemplo n.º 2
0
def runner(message):
    message = message.split(" ")
    stop_id = message[0]
    all_data = parse(stop_id)
    all_data = decode_api(all_data)

    response = ""

    for data in all_data:
        if not isinstance(data, int) and "schedules" in data:
            if (len(message) > 1
                    and data["name"] in message) or len(message) == 1:
                response = response + data["name"] + ":("
                for sched in data["schedules"]:
                    if sched["tripcancel"] == "false" and sched[
                            "stopcancel"] == "false":
                        if len(sched["time"]) > 11:
                            sched["time"] = sched["time"][:-10]
                        response = response + sched["time"] + ","
                response = response + ") "
    print(len(response))
    return response
Ejemplo n.º 3
0
    'nth': lambda x, i: x[i] if x else None,

    # Function functions
    # map - (variadic) Returns a list with the function applied to each item - (map square (list 1 2 3)) -> (1 4 9)
    'map': lambda func, *args: List(map(func, args)),
    # apply - (variadic) Returns result of function applied to all items - (apply eval deferred-commands)
    'apply': lambda x, *y: x(*y),
    # doc - Return the doc string of a function
    'doc': lambda x: x.doc,
    # help - Same as doc
    'help': lambda x: x.doc,
    # setdoc - Set the doc string of a user defined function - (setdoc myfunc "A helpful function.")
    'setdoc': lambda x, y: x.setdoc(y),

    # System type commands
    # display - (variadic) Display items on screen (variadic)
    'display': display,
    ## There is no 'close' for files. Files are handled in a big chunk and automatically closed.
    # import - Read and apply a file (import "myfile.pwl") = (apply eval (read-file "myfile.pwl"))
    'import': pwl_import,
    # read-file - Create a list of strings from a file
    'readfile': lambda file: open(file).read(),
    # read-line - Return a string from console input.
    'readline': read_line,
    # parse
    'parse': lambda x: parse(x)[0],
    # time - Returns an int of time in ms from the start of the Unix epoch (January first 1970)
    'time': lambda: int(round(time.time() * 1000))
    # *argv* - This is defined in pwlisp.py. It is a list of command line arguments.
}
Ejemplo n.º 4
0
def result(file_to_run):
    parse('uploads/' + file_to_run)

    return 'Under construction'
Ejemplo n.º 5
0
def validate_request(file):
    global JSONDATA
    JSONDATA = order_parser.parse(file)
    orders = JSONDATA['orders'][::-1]

    JSONDATA['orders'] = validator1.validate_orders(orders)
Ejemplo n.º 6
0
def result(file_to_run):
    parse('uploads/' + file_to_run)

    return 'Under construction'
Ejemplo n.º 7
0
def Evaluate(exp, environment):
    global debug
    global depth
    depth += 1

    if debug:
        print_debug('Evaluate: {} {}'.format(exp, str(types.pwl_type(exp))),
                    depth)

    while True:
        # macroexpand

        if type(exp) != types.List:
            depth -= 1
            return eval_list(exp, environment)

        if len(exp) == 0:
            depth -= 1
            return exp

        # Special forms

        # Define
        if exp[0] == 'define':
            definition = Evaluate(exp[2], environment)
            if type(definition) == types.Function:
                definition.name = exp[1]
            depth -= 1
            return environment.set(exp[1], definition)
        # Define macro
        # Quote
        elif exp[0] == 'quote':
            depth -= 1
            return exp[1]
        # Import
        elif exp[0] == 'import':
            file_name = Evaluate(exp[1], environment)
            contents = open(file_name).read()
            result = parse(contents, file_name)
            for item in result:
                if debug:
                    print_debug('\nImport result: {}'.format(repr(item)),
                                depth)
                Evaluate(item, environment)
            depth -= 1
            return "Success."
        # If
        elif exp[0] == 'if':
            condition = Evaluate(exp[1], environment)
            exp = exp[2] if condition else exp[3]

        # Or
        elif exp[0] == 'or':
            evaluands = exp[1:]
            result = None
            for item in evaluands:
                result = Evaluate(item, environment)
                if result:
                    break
            depth -= 1
            return result
        # And
        elif exp[0] == 'and':
            evaluands = exp[1:]
            result = None
            for item in evaluands:
                result = Evaluate(item, environment)
                if not result:
                    break
            depth -= 1
            return result
        # Try/catch
        # Env
        elif exp[0] == 'env':
            if len(exp) > 1:
                if environment.find(exp[1]):
                    result = environment.get(exp[1])
                else:
                    result = '{} was not found.'.format(exp[1])
            else:
                result = str(environment)
            depth -= 1
            return result

        # For debugging.
        elif exp[0] == 'debug':
            debug = not debug
            exp = debug

        elif exp[0] == 'let':
            #(let (a 7 b 8) (+ 1 b))
            # Make a new environment with a = 7, b = 8
            # Evaluate exp[2] using new environment
            new_env = Environment(environment)
            if type(exp[1]) != types.List:
                raise types.Error('Expected a binding list, got {}.'.format(
                    exp[1]))
                return None
            bindlist = types.List(exp[1])
            if len(bindlist) % 2 != 0:
                raise types.Error('Missing argument for bind list: {}'.format(
                    str(exp[1])))
            while bindlist:
                if debug:
                    print_debug(
                        'let binding {} to {}.'.format(bindlist[0],
                                                       bindlist[1]), depth)
                new_env.set(bindlist[0], Evaluate(bindlist[1], new_env))
                bindlist = bindlist[2:]
            if debug:
                print_debug('let environment:\n{}'.format(str(new_env)), depth)
            exp = exp[2]
            environment = new_env
        # Do - Evaluate everything in the list and return only the last result
        elif exp[0] == 'do':
            exp = exp[1:]
            result = eval_list(exp, environment)
            exp = result[-1]
        # Function
        elif exp[0] == 'function':
            func = exp[0]
            params = exp[1]
            body = exp[2]
            if debug:
                print_debug(
                    'Function created with: {} {}.'.format(params, body),
                    depth)
            fn = types.Function('user function',
                                None,
                                params,
                                environment,
                                body,
                                user=True)
            depth -= 1
            return fn
        # Else apply function
        else:
            items = eval_list(exp, environment)
            func = items[0]
            if debug:
                print_debug('Executing: {}'.format(str(func)), depth)
                print_debug('     Args: {}'.format(str(items[1:])), depth)
            if func.is_builtin:
                depth -= 1
                return func(*items[1:])
            environment = Environment(func.env, func.params, items[1:])
            exp = func.expression
Ejemplo n.º 8
0
def Read(string):
    return parse(string)