#!/usr/bin/env python3
import string
import random
from pathlib import Path

MAX_WORD_LEN = 10
MIN_WORD_LEN = 6
WORDLIST_PATH = Path(__file__).parent / "wordlists/words_alpha.txt"

def check_repeating_chars(word):
    last_char = None
    for c in word:
        if c == last_char:
            return True
        else:
            last_char = c

    return False

def gen_pass(dict_file=WORDLIST_PATH):
    wordlist = []
    with open(dict_file, 'r') as f:
        lines = f.read().splitlines()
        for i in range(len(lines)):
            if (not (MIN_WORD_LEN <= len(lines[i]) <= MAX_WORD_LEN)
                or check_repeating_chars(lines[i])):
                continue

            wordlist.append(lines[i][0].upper() + lines[i][1:])

    other_chars = [string.punctuation, string.digits, string.digits]
    random.shuffle(other_chars)

    return (
        random.choice(wordlist) +
        random.choice(other_chars[0]) +
        random.choice(wordlist) +
        random.choice(other_chars[1]) +
        random.choice(wordlist) +
        random.choice(other_chars[2])
    )

def main():
    print(gen_pass())

if __name__ == '__main__':
    main()
