def main(): message = \ """ USAGE: password_generator [length=LENGTH] [symbols] """ # Logging definition logger = logging_class.PersonalLog(sys.argv[0]) # Default setting length = 15 symbol = False # Command input recognition re_length = re.compile(r'^length=(\d+)$', re.IGNORECASE) re_symbol = re.compile(r'symbols', re.IGNORECASE) for option in sys.argv: if re_symbol.search(option) != None: symbol = True re_match = re_length.search(option) if re_match != None: length = int(re_match.group(1)) logger.debug('Symbol Status: {}'.format(symbol)) logger.debug('Length: {}'.format(length)) # Generate password user_password = Password(length, symbol) user_password.set_password() # Write password to text file PasswordGenerated.txt with open('PasswordGenerated.txt', 'w') as write_file: write_file.write(user_password.password + '\n') logger.debug('Password: {}'.format(user_password.password)) print('Write new generated password to PasswordGenerated.txt.')
def main(): message = \ """ USAGE: lastpass_backup.py DESTINATION_DIRECTORY """ # Check program syntax usage try: output_dir = blkcl.Directory(sys.argv[1]) except IndexError: print(message) sys.exit(1) # Check directory existence if not output_dir.dir_exist(): print('Target directory {} not exist.'.format(output_dir.dir)) sys.exit(11) # Create logger file global logger logger = lgcl.PersonalLog('lastpass_backup', directory=output_dir.dir) # Password file creation print('Press CTRL-C to exit.\n') while True: try: # Get password information information = _request_info() # Write to file _password_backup(information, output_dir.dir) except FileExistsError: continue except KeyboardInterrupt: print('\nlastpass_backup exit.') sys.exit(0)
'N': 22, 'O': 35, 'P': 23, 'Q': 24, 'R': 25, 'S': 26, 'T': 27, 'U': 28, 'V': 29, 'W': 32, 'X': 30, 'Y': 31, 'Z': 33 } logger = lgcl.PersonalLog('id_generator') def main(): """ USAGE: id_generator.py """ checksum = 0 personal_id = '' # Randomly choose a LETTER letter = random.choice(list(LETTERS)) alpha_num = LETTERS[letter] checksum = (alpha_num // 10) + (alpha_num % 10) * 9 personal_id += letter
Error Code: 1 - Program usage error 11 - Personal ID format error """ import sys, re import logging_class as lgcl LETTERS = {'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15, 'G': 16, 'H': 17, 'I': 34, 'J': 18, 'K': 19, 'L': 20, 'M': 21, 'N': 22, 'O': 35, 'P': 23, 'Q': 24, 'R': 25, 'S': 26, 'T': 27, 'U': 28, 'V': 29, 'W': 32, 'X': 30, 'Y': 31, 'Z': 33} logger = lgcl.PersonalLog('id_identifier') def main(): message = \ """ USAGE: id_identifier.py PERSONAL_ID """ checksum = 0 # Check program usage try: personal_id = sys.argv[1] except IndexError: print(message)
Error Code: 1 - Program usage error 3 - Read input file IO Error 11 - Input file existence error 13 - Output file existence error 15 - File extension type error """ import sys, re import html, collections, hashlib import logging_class as lgcl import block_class as blkcl logger = lgcl.PersonalLog('url_extractor') URL_REGEX = r'((http)(s)?(\S)*(\.jpg|\.jpeg|\.png))' FILE_FORMATS = ('.txt') def main(): message = \ """ USAGE: url_extractor.py INPUTFILE OUTPUTFILE """ global FILE_FORMATS # Check input arguments try: