mirror of
https://github.com/SinTan1729/recipe-box-for-wikijs.git
synced 2025-04-19 18:09:59 -05:00
Compare commits
3 commits
81269e74eb
...
58da47c04a
Author | SHA1 | Date | |
---|---|---|---|
58da47c04a | |||
2aa5a0ff23 | |||
4e79d2163d |
1 changed files with 6 additions and 4 deletions
|
@ -62,7 +62,9 @@ def valid_filename(directory, filename=None):
|
||||||
directory = os.path.dirname(directory)
|
directory = os.path.dirname(directory)
|
||||||
|
|
||||||
# Allow for directories.
|
# Allow for directories.
|
||||||
items = set(os.listdir(directory))
|
ensure_directory_exists(directory)
|
||||||
|
items = os.listdir(directory)
|
||||||
|
|
||||||
if filename in items:
|
if filename in items:
|
||||||
count = 1
|
count = 1
|
||||||
while test_filename(filename, count) in items:
|
while test_filename(filename, count) in items:
|
||||||
|
@ -82,10 +84,10 @@ def process_recipe(config, scraper, url, verbose=False):
|
||||||
recipe_box = ensure_directory_exists(config['recipe_box'])
|
recipe_box = ensure_directory_exists(config['recipe_box'])
|
||||||
media = ensure_directory_exists(os.path.join(config['recipe_box'], 'images'))
|
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 = os.path.join(recipe_box, prefix + '.md')
|
||||||
path = valid_filename(path)
|
path = valid_filename(path)
|
||||||
recipe = open(path, 'w')
|
recipe = open(path, 'w+')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
image_url = scraper.image()
|
image_url = scraper.image()
|
||||||
|
@ -97,7 +99,7 @@ def process_recipe(config, scraper, url, verbose=False):
|
||||||
# Also, os.path.splitext(url), probably not a good idea. ;)
|
# 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]
|
filename = os.path.splitext(os.path.basename(path))[0] + os.path.splitext(scraper.image())[1]
|
||||||
filepath = os.path.join(media, filename)
|
filepath = os.path.join(media, filename)
|
||||||
image = open(filepath, 'wb')
|
image = open(filepath, 'wb+')
|
||||||
image.write(response.content)
|
image.write(response.content)
|
||||||
image.close()
|
image.close()
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
Loading…
Reference in a new issue