diff --git a/totp.py b/totp.py index d84858c..0624850 100755 --- a/totp.py +++ b/totp.py @@ -26,6 +26,7 @@ def get_arguments(): parser.add_argument("site", nargs="*") default_cfg_path = os.environ['HOME'] + '/.totprc' parser.add_argument("-c", "--config", default=default_cfg_path, help='Path to config-file. Defaults to ~/.totprc') + parser.add_argument("-a", "--andOTP", help='Path to andOTP backup file') args = parser.parse_args() return args @@ -74,13 +75,13 @@ def read_config(args): if not os.path.isfile(config.get('totp', 'andOTPfile')): die("The file %s does not exist" % config.get('totp', 'andOTPfile')) - return config + return config.get('totp', 'andOTPfile') -def read_file(config): +def read_file(andOTPfile): # Open and parse the data file try: - with open(config.get('totp', 'andOTPfile')) as filen: + with open(andOTPfile) as filen: data = json.load(filen) except: die("Error parsing JSON, corrupt andOTP-file?") @@ -129,9 +130,12 @@ class TOTP(): if __name__ == '__main__': - args = get_arguments() # Get args from cmdline - cfg = read_config(args) # Read from the cfg file - data = read_file(cfg) # Open the data file + args = get_arguments() # Get args from cmdline + if args.andOTP: + andOTPfile = args.andOTP + else: + andOTPfile = read_config(args) # Read from the cfg file + data = read_file(andOTPfile) # Open the data file if not args.site: # Show a menu if no input while True: