Example #1
0
class Unscrambler:
    def __init__(self, options):
        self.database = None
        
        if options.first_run:
            self.database = DataBase(options.database_dir, new=True)
        else:
            self.database = DataBase(options.database_dir)
        
        if options.add_wordlist is not None:
            with open(options.add_wordlist, 'r') as file:
                
                count = 0
                for word in file:
                    word = word.lower()
                    word = word.replace("\n", "")
                    
                    #Checks if word is legal
                    valid = True
                    for char in word:
                        if char not in ALPHABET:
                            valid = False
                            print("\"%s\" contains invalid characters" % word)
                            break
                        
                    if not valid:
                        continue 

                    if not self.database.hasWord(word):
                       self.database.addWord(word)
                       count += 1
                       
                print("Added %s valid words to database" % count)
                    
            self.database.close()
            sys.exit(0)
            
        if options.add_pattern is not None:
            #print(options.add_pattern)
            self.database.addPattern(options.add_pattern)
        
        self.database.close()