| 12 | |
| 13 | # modify PDF list based on type (exclude/include) |
| 14 | def modify(pdfs, type): |
| 15 | pdf_selections = input( |
| 16 | "\nEnter the PDF filenames which should be excluded/included from the list separated by a SPACE:\n> " |
| 17 | ).split() |
| 18 | |
| 19 | # store user's selections |
| 20 | final_selections = [] |
| 21 | |
| 22 | # check if files exist |
| 23 | for selection in pdf_selections: |
| 24 | if selection not in pdfs: |
| 25 | print( |
| 26 | f"\n❗️ {selection} does not exist in this directory! Skipping it...\n" |
| 27 | ) |
| 28 | else: |
| 29 | print(f"\n❌ Removing '{selection}' from merger...") |
| 30 | final_selections.append(selection) |
| 31 | |
| 32 | # include/exclude PDFs |
| 33 | for selection in final_selections: |
| 34 | if type == "exclude": |
| 35 | pdfs = list(filter(lambda x: x != selection, pdfs)) |
| 36 | else: |
| 37 | pdfs = list(filter(lambda x: x == selection, pdfs)) |
| 38 | |
| 39 | # return modified list |
| 40 | return pdfs |
| 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |