file error handling
This commit is contained in:
parent
f5619b9ef8
commit
010334e2c9
|
@ -50,14 +50,19 @@ def main():
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
fnf = 'error: file not found. please provide a path to a really-existing file!'
|
||||||
|
|
||||||
# if a combine file is provided, combine it w/ input file:
|
# if a combine file is provided, combine it w/ input file:
|
||||||
if args.combine :
|
if args.combine :
|
||||||
# get raw text as a string for both files:
|
# get raw text as a string for both files:
|
||||||
with open(args.infile, encoding="latin-1") as f:
|
try:
|
||||||
text = f.read()
|
with open(args.infile, encoding="latin-1") as f:
|
||||||
|
text = f.read()
|
||||||
with open(args.combine, encoding="latin-1") as cf:
|
with open(args.combine, encoding="latin-1") as cf:
|
||||||
ctext = cf.read()
|
ctext = cf.read()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(fnf)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# build the models and build a combined model:
|
# build the models and build a combined model:
|
||||||
# NB: attempting to implement Newline option here (and below):
|
# NB: attempting to implement Newline option here (and below):
|
||||||
|
@ -91,13 +96,17 @@ def main():
|
||||||
# if no combo file, just do normal:
|
# if no combo file, just do normal:
|
||||||
else:
|
else:
|
||||||
# Get raw text as string.
|
# Get raw text as string.
|
||||||
with open(args.infile, encoding="latin-1") as f:
|
try:
|
||||||
text = f.read()
|
with open(args.infile, encoding="latin-1") as f:
|
||||||
|
text = f.read()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(fnf)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# Build the model:
|
# Build the model:
|
||||||
# NB: this errors if infile is EMPTY:
|
# NB: this errors if infile is EMPTY:
|
||||||
|
|
||||||
## implement newline option here:
|
## newline option:
|
||||||
if args.newline :
|
if args.newline :
|
||||||
text_model = markovify.NewlineText(text,
|
text_model = markovify.NewlineText(text,
|
||||||
state_size=args.state_size, well_formed=args.no_well_formed)
|
state_size=args.state_size, well_formed=args.no_well_formed)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -7,7 +7,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
setup(name='mkv-this',
|
setup(name='mkv-this',
|
||||||
version='0.1.25',
|
version='0.1.26',
|
||||||
description='cli wrapper for markovify: take a text file, markovify, output the results to a text file.',
|
description='cli wrapper for markovify: take a text file, markovify, output the results to a text file.',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
|
Loading…
Reference in New Issue