Skip to content

Commit

Permalink
Updated readme and pylint feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
navchandar authored Nov 21, 2023
1 parent 2dc96c9 commit 6ef0d76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ scanner -i .\tests -f "test.pdf"
# Convert all jpg, jpeg, png, webp files in folder to one pdf file
scanner -i .\tests -f "image"

# Convert all image files in folder in the order of file names
scanner -i .\tests -f "image" -s "name"

# Convert all png files in folder to pdf with 100% quality to one pdf file
scanner -i .\tests -f "png" -q 100

Expand Down Expand Up @@ -101,6 +104,9 @@ These are the command-line arguments accepted:
- `-r, --recurse` : Allows scripts to find all matching files including subdirectories. Accepted values are "yes" or "no". The default value is "yes".
- Example: `-r yes` or `--recurse no`

- `-s, --sort_by` : Allows scripts to sort the files based on name, creation time or modified time. Accepted values are "name", "ctime", "mtime", "none". The default value is "name". If "none" is selected, then the default order of files returned by the OS is used for document conversion.
- Example: `-s name` or `--sort_by none`


❗❗ **Note:** ❗❗

Expand Down
6 changes: 4 additions & 2 deletions scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def get_blackandwhite(args):
return _is_true(args.black_and_white)

def get_sort_key(args):
"""Return the key with which files should be sorted and then coverted"""
sort_by = args.sort_by.lower().strip()
return {"name": os.path.abspath, "ctime": os.path.getctime, "mtime": os.path.getmtime}.get(sort_by)
key_map = {"name": os.path.abspath, "ctime": os.path.getctime, "mtime": os.path.getmtime}
return key_map.get(sort_by)

def get_file_type(args):
"""Get file type and supported documents based on input arguments"""
Expand Down Expand Up @@ -433,7 +435,7 @@ def find_matching_files(input_folder, file_type_list, recurse=False, sort_key=No
print_color(f"Permission denied: {input_folder}", "red")
except Exception as err:
print_color(f"Error when searching for files: {err}", "red")

# Sort the list of files if sorting is requested by user
if sort_key:
files_list.sort(key=sort_key)
Expand Down

0 comments on commit 6ef0d76

Please sign in to comment.