file error handling

This commit is contained in:
mouse 2020-04-21 12:02:45 -03:00
parent f5619b9ef8
commit 010334e2c9
2 changed files with 18 additions and 9 deletions

View File

@ -50,14 +50,19 @@ def main():
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 args.combine :
# get raw text as a string for both files:
with open(args.infile, encoding="latin-1") as f:
text = f.read()
with open(args.combine, encoding="latin-1") as cf:
ctext = cf.read()
try:
with open(args.infile, encoding="latin-1") as f:
text = f.read()
with open(args.combine, encoding="latin-1") as cf:
ctext = cf.read()
except FileNotFoundError:
print(fnf)
sys.exit()
# build the models and build a combined model:
# NB: attempting to implement Newline option here (and below):
@ -91,13 +96,17 @@ def main():
# if no combo file, just do normal:
else:
# Get raw text as string.
with open(args.infile, encoding="latin-1") as f:
text = f.read()
try:
with open(args.infile, encoding="latin-1") as f:
text = f.read()
except FileNotFoundError:
print(fnf)
sys.exit()
# Build the model:
# NB: this errors if infile is EMPTY:
## implement newline option here:
## newline option:
if args.newline :
text_model = markovify.NewlineText(text,
state_size=args.state_size, well_formed=args.no_well_formed)

View File

@ -7,7 +7,7 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
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.',
long_description=long_description,
long_description_content_type='text/markdown',