Example #1
0
def main():
    client = pymongo.MongoClient()
    db = client.lowfarm

    utils.cls()
    utils.hr()
    command_info()
    utils.hr()
    sys.stdout.write('Enter a command: ')

    previous_command = ''

    while True:
        try:
            input_command = raw_input()
        except:
            sys.stdout.write('\n')
            break
        if input_command == 'quit':
            print('Bye')
            break

        if input_command == '':
            input_command = previous_command

        previous_command = input_command

        if not process_commands(db, input_command):
            print('Command not regognised... Try again')

        utils.hr()
        sys.stdout.write('Enter a command: ')
        time.sleep(0.1)
Example #2
0
def process_commands(db, input_command):
    utils.cls()
    utils.hr()
    command_info()
    utils.hr()
    if input_command == '':
        return False

    for command_group in commands:
        for command_set in commands[command_group]:
            for command in [command_set[0], command_set[1]]:
                match = re.match('^{0}(?: (?P<data>.+))?$'.format(command), input_command)
                if match is not None:
                    command_set[2](db, match.group('data'))
                    return True
    return False