From 2aa5a0ff23c6738b8c1b2a89d2370f55d09cdf73 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Wed, 5 Mar 2025 23:30:40 -0600 Subject: [PATCH] fix: Create file if does not exist --- recipe_box.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/recipe_box.py b/recipe_box.py index 1bc8650..b23339d 100755 --- a/recipe_box.py +++ b/recipe_box.py @@ -86,10 +86,10 @@ def process_recipe(config, scraper, url, verbose=False): recipe_box = ensure_directory_exists(config['recipe_box']) media = ensure_directory_exists(os.path.join(config['recipe_box'], 'images')) - prefix = scraper.title().replace(' ', '-').lower() + prefix = scraper.title().strip().replace(' ', '-').lower() path = os.path.join(recipe_box, prefix + '.md') path = valid_filename(path) - recipe = open(path, 'w') + recipe = open(path, 'w+') try: image_url = scraper.image() @@ -101,7 +101,7 @@ def process_recipe(config, scraper, url, verbose=False): # Also, os.path.splitext(url), probably not a good idea. ;) filename = os.path.splitext(os.path.basename(path))[0] + os.path.splitext(scraper.image())[1] filepath = os.path.join(media, filename) - image = open(filepath, 'wb') + image = open(filepath, 'wb+') image.write(response.content) image.close() if verbose: