From 82da427d1a4cf6472184d9766aa890232f8c0241 Mon Sep 17 00:00:00 2001 From: scito Date: Sat, 24 Dec 2022 02:56:40 +0100 Subject: [PATCH] refactor code: extract method --- extract_otp_secret_keys.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extract_otp_secret_keys.py b/extract_otp_secret_keys.py index ea3ab50..599e461 100644 --- a/extract_otp_secret_keys.py +++ b/extract_otp_secret_keys.py @@ -139,8 +139,14 @@ def extract_otps(args): def get_lines_from_file(filename): - global verbose + lines = read_lines_from_text_file(filename) + if lines != None: + return lines + # could not process text file, try reading as image + return convert_img_to_line(filename) + +def read_lines_from_text_file(filename): if filename != '=': check_file_exists(filename) finput = fileinput.input(filename) @@ -158,11 +164,12 @@ def get_lines_from_file(filename): if filename == '-': abort('\nERROR: Unable to open text file form stdin. ' 'In case you want read an image file from stdin, you must use "=" instead of "-".') - # else: The file is probably an image, process below + else: # The file is probably an image, process below + return None finally: finput.close() - # could not process text file, try reading as image +def convert_img_to_line(filename): if filename != '-': try: if filename != '=':