#!/usr/bin/env python3

import string
import time as t
# Uncomment below line if you are using windows and you want to be notified by sound when it's complete.
# import winsound
import random
import sys

def generate_file_name(f_name):
    if f_name != "" or f_name != " ":
        local_time_as_str = t.strftime("%S_%d_%m_%Y")
        file_name = "password_list_" + local_time_as_str + ".txt "
    else:
        file_name = "password_list_" + f_name + ".txt"


    return file_name

def generate_word(max_c):
    return ''.join(random.SystemRandom().choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(0, max_c))

def generate_words_list(max_c, max_len, save_name ):

    f = open("saved_lists/"+save_name, "w+")

    # Uncomment for Debug
    # print(max_c)
    # print(max_len)
    # print(save_name)

    timer_start = t.time()

    for count in range(int(max_len)+1):
        word = generate_word(max_c)
        f.write(word + "\n")
        print(count,"of", int(max_len),"generated.", end="\r")

    print("\n\n")

    if count == int(max_len):
        # If you are using windows and you want to be notified when it's complete uncomment the below line.
        # winsound.PlaySound("SystemDefault", winsound.SND_ALIAS)
        timer_end = t.time()
        time_to_generate = timer_end - timer_start
        print("Time took to generate %s Passwords: %.3fs" % (max_len, time_to_generate))
        print("Your Passwords have been generated.")
        print("Your Passwords have been saved to ", save_name)
        t.sleep(3)

    f.close()



def main():
    d_max_char = 26
    d_max_len = 916132832

    print("\n\n")

    # Name
    print("Help Text: \nNot Required - Default = words_dict_ and the date.")
    dict_name = input("[*] - The Name of the dictionary: ")

    print("\n")

    # Max
    print("Help Text: \nRequired - Default = 26 characters")
    max_char = input("[*] - The maximum number of characters a word can have: ")

    print("\n")

    # Max Gen
    print("Help Text: \n Required - Default = 916132832 words.")
    print("[!] --- WARNING! --- \nDo not leave this blank. \nIt may take up to 5 hours to generate 916132832 Passwords for LOW-END PC's. \nA number below 100000 is Recommended for LOW-END PC's.")
    max_d_wo = input("[*] - The max number of words to be generated in the dictionary: ")

    print("\n\n")


    if max_char == "" or max_char == " ":
        max_char = d_max_char

    if max_d_wo == "" or max_d_wo == " ":
        max_d_wo = d_max_len

    max_char = int(max_char)
    max_d_wo = int(max_d_wo)

    generate_words_list(max_char, max_d_wo, generate_file_name(dict_name))

if __name__ == '__main__':
    main()
