Skip to content

Commit

Permalink
Allow for multiple input files
Browse files Browse the repository at this point in the history
Everything is merged together
  • Loading branch information
aanker committed Oct 30, 2022
1 parent 09f91f6 commit a0a32ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions xwordlist.conf
Expand Up @@ -8,7 +8,10 @@
#################################################################################################

### Input text file
### To specify one file:
# input list_of_words_or_text.txt
### To specify multiple files:
# input [file1.txt, file2.txt, ...]

### Input web URL
# webpage URL
Expand Down
17 changes: 11 additions & 6 deletions xwordlist.py
Expand Up @@ -291,7 +291,7 @@ def setup_output(localArgs, otherArgs):
if localArgs.output:
outputFile = localArgs.output
elif localArgs.input or localArgs.urllist:
fileName = localArgs.input if localArgs.input else localArgs.urllist
fileName = localArgs.input[0] if localArgs.input else localArgs.urllist
filePieces = os.path.splitext(fileName)
outputFile = f'{filePieces[0]}_{file_add}{filePieces[1]}'
elif localArgs.webpage:
Expand Down Expand Up @@ -322,9 +322,10 @@ def setup_input(localArgs, otherArgs):

# Load input(s)
if localArgs.input:
fileWords = get_file_content(localArgs.input)
if fileWords:
returnWords.extend(fileWords)
for inputFile in localArgs.input:
fileWords = get_file_content(inputFile)
if fileWords:
returnWords.extend(fileWords)

if localArgs.webpage:
webWords = get_web_page(localArgs.webpage, localArgs.container, localArgs.webextract)
Expand Down Expand Up @@ -438,7 +439,7 @@ def main():
parser.add_argument('--config', action='store_true', help='locate your config file and quit')

# Input and output options
parser.add_argument('-i', '--input', type=pathlib.Path, help='Input text file')
parser.add_argument('-i', '--input', nargs='*', type=pathlib.Path, help='Input one or more text file(s)')
parser.add_argument('-w', '--webpage', help='Input web URL')
parser.add_argument('--urllist', type=pathlib.Path, help='Input multiple URLs in a document')
output_help = 'Output text file: if no name specified, a default name is created'
Expand Down Expand Up @@ -508,7 +509,11 @@ def main():
# See if a default directory was specified and rewrite inputs and outputs as necessary
if confArgs.directory is not None:
if pathlib.Path(confArgs.directory).is_dir():
confArgs.input = os.path.join(confArgs.directory, confArgs.input) if confArgs.input else None
if confArgs.input:
inputFiles = []
for inputFile in confArgs.input:
inputFiles.append(os.path.join(confArgs.directory, inputFile) if inputFile else None)
confArgs.input = inputFiles
confArgs.urllist = os.path.join(confArgs.directory, confArgs.urllist) if confArgs.urllist else None
confArgs.output = os.path.join(confArgs.directory, confArgs.output) if confArgs.output else None
else:
Expand Down

0 comments on commit a0a32ad

Please sign in to comment.