Exemple #1
0
def main():
    parser = argparse.ArgumentParser(description="Labwork")

    parser.add_argument("--sort", "-s", action="store",
                        nargs=1, type=str,
                        help=sortHelp)
    parser.add_argument("--genunsort", "-gus", action="store",
                        nargs=4, type=str,
                        help=gustHelp)
    parser.add_argument("--fib", "-f", action="store",
                        nargs=1, type=int,
                        help=fibHelp)
    parser.add_argument("--storage", "-st", action="store_true",
                        help=storageHelp)
    parser.add_argument("--text", "-t", action="store",
                        nargs=1, type=str,
                        help=textHelp)
    parser.add_argument("--ngram", "-ng", action="store",
                        nargs=2, type=int,
                        help=ngramHelp)
    parser.add_argument("--valid", "-v", action="store",
                        nargs=2, type=str,
                        help=validHelp)

    args = parser.parse_args()

    if args.sort:
        sort.sort_all(sort.read_unsorted_file(args.sort[0].strip()))
    elif args.genunsort:
        sort.gen_unsorted_file(args.genunsort[0].strip(),
                               int(args.genunsort[1].strip()),
                               int(args.genunsort[2].strip()),
                               int(args.genunsort[3].strip()))
    elif args.storage:
        storage.element_storage()
    elif args.fib:
        fib.print_fib(args.fib[0])
    elif args.text:
        count = 10
        n = 4
        if args.ngram:
            count = args.ngram[0]
            n = args.ngram[1]

        text.analyze_(args.text[0].strip(), count, n)
    elif args.valid:
        if args.valid[0] == "url":
            validator.get_url_parts(args.valid[1])
        elif args.valid[0] == "email":
            validator.validate_email(args.valid[1])
        elif args.valid[0] == "real":
            validator.validate_real_num(args.valid[1])
    else:
        print("Please, enter --help")
Exemple #2
0
def main():
    parser = createParser()
    argument = parser.parse_args(sys.argv[1:])
    try:
        if argument.task == 1:
            if argument.subtask == 1:
                with open(argument.file, 'r') as file:
                    text.repeats(file)
            elif argument.subtask == 2:
                with open(argument.file, 'r') as file:
                    text.average(file)
            elif argument.subtask == 3:
                with open(argument.file, 'r') as file:
                    text.median(file)
            elif argument.subtask == 4:
                with open(argument.file, 'r') as file:
                    text.top(file)
        elif argument.task == 2:
            if argument.subtask == 1:
                lst = raw_input("Enter list: ").split()
                lst = [int(elem) for elem in lst]
                print sort.quicksort(lst)
            elif argument.subtask == 2:
                lst = raw_input("Enter list: ").split()
                lst = [int(elem) for elem in lst]
                print sort.mergesort(lst)
            elif argument.subtask == 3:
                lst = raw_input("Enter list: ").split()
                lst = [int(elem) for elem in lst]
                print sort.radixsort(lst)
        elif argument.task == 3:
            storage.storage()
        elif argument.task == 4:
            n = int(raw_input("Enter n: "))
            fib.print_fib(n)
    except Exception as e:
        print e