Use pathclass.Path.open.
This commit is contained in:
parent
0bd52eb08b
commit
3373e36f64
5 changed files with 6 additions and 6 deletions
|
@ -95,7 +95,7 @@ def breakdown_argparse(args):
|
||||||
breakdown_basename = breakdown_basename % database.filepath.replace_extension('').basename
|
breakdown_basename = breakdown_basename % database.filepath.replace_extension('').basename
|
||||||
breakdown_filepath = database.breakdown_dir.with_child(breakdown_basename)
|
breakdown_filepath = database.breakdown_dir.with_child(breakdown_basename)
|
||||||
os.makedirs(breakdown_filepath.parent.absolute_path, exist_ok=True)
|
os.makedirs(breakdown_filepath.parent.absolute_path, exist_ok=True)
|
||||||
breakdown_file = open(breakdown_filepath.absolute_path, 'w')
|
breakdown_file = breakdown_filepath.open('w')
|
||||||
with breakdown_file:
|
with breakdown_file:
|
||||||
breakdown_file.write(dump)
|
breakdown_file.write(dump)
|
||||||
print('Wrote', breakdown_filepath.relative_path)
|
print('Wrote', breakdown_filepath.relative_path)
|
||||||
|
|
|
@ -16,14 +16,14 @@ def get_styles(subreddit):
|
||||||
|
|
||||||
stylesheet_filepath = database.styles_dir.with_child('stylesheet.css')
|
stylesheet_filepath = database.styles_dir.with_child('stylesheet.css')
|
||||||
print('Downloading %s' % stylesheet_filepath.relative_path)
|
print('Downloading %s' % stylesheet_filepath.relative_path)
|
||||||
with open(stylesheet_filepath.absolute_path, 'w', encoding='utf-8') as stylesheet:
|
with stylesheet_filepath.open('w', encoding='utf-8') as stylesheet:
|
||||||
stylesheet.write(styles.stylesheet)
|
stylesheet.write(styles.stylesheet)
|
||||||
|
|
||||||
for image in styles.images:
|
for image in styles.images:
|
||||||
image_basename = image['name'] + '.' + image['url'].split('.')[-1]
|
image_basename = image['name'] + '.' + image['url'].split('.')[-1]
|
||||||
image_filepath = database.styles_dir.with_child(image_basename)
|
image_filepath = database.styles_dir.with_child(image_basename)
|
||||||
print('Downloading %s' % image_filepath.relative_path)
|
print('Downloading %s' % image_filepath.relative_path)
|
||||||
with open(image_filepath.absolute_path, 'wb') as image_file:
|
with image_filepath.open('wb') as image_file:
|
||||||
response = requests.get(image['url'])
|
response = requests.get(image['url'])
|
||||||
image_file.write(response.content)
|
image_file.write(response.content)
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ def get_wiki(subreddit):
|
||||||
|
|
||||||
wikipage_path = database.wiki_dir.join(wikipage.name).replace_extension('md')
|
wikipage_path = database.wiki_dir.join(wikipage.name).replace_extension('md')
|
||||||
os.makedirs(wikipage_path.parent.absolute_path, exist_ok=True)
|
os.makedirs(wikipage_path.parent.absolute_path, exist_ok=True)
|
||||||
with open(wikipage_path.absolute_path, 'w', encoding='utf-8') as handle:
|
with wikipage_path.open('w', encoding='utf-8') as handle:
|
||||||
handle.write(wikipage.content_md)
|
handle.write(wikipage.content_md)
|
||||||
print('Wrote', wikipage_path.relative_path)
|
print('Wrote', wikipage_path.relative_path)
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ def index_worker(
|
||||||
mash_basename += suffix + extension
|
mash_basename += suffix + extension
|
||||||
mash_filepath = database.index_dir.with_child(mash_basename)
|
mash_filepath = database.index_dir.with_child(mash_basename)
|
||||||
|
|
||||||
mash_handle = open(mash_filepath.absolute_path, 'w', encoding='UTF-8')
|
mash_handle = mash_filepath.open('w', encoding='UTF-8')
|
||||||
if html:
|
if html:
|
||||||
mash_handle.write(HTML_HEADER)
|
mash_handle.write(HTML_HEADER)
|
||||||
line_format = LINE_FORMAT_HTML
|
line_format = LINE_FORMAT_HTML
|
||||||
|
|
|
@ -385,7 +385,7 @@ def offline_reading(subreddit=None, username=None, specific_submission=None):
|
||||||
for (id, html) in htmls:
|
for (id, html) in htmls:
|
||||||
html_basename = '%s.html' % id
|
html_basename = '%s.html' % id
|
||||||
html_filepath = database.offline_reading_dir.with_child(html_basename)
|
html_filepath = database.offline_reading_dir.with_child(html_basename)
|
||||||
html_handle = open(html_filepath.absolute_path, 'w', encoding='utf-8')
|
html_handle = html_filepath.open('w', encoding='utf-8')
|
||||||
html_handle.write(html)
|
html_handle.write(html)
|
||||||
html_handle.close()
|
html_handle.close()
|
||||||
print('Wrote', html_filepath.relative_path)
|
print('Wrote', html_filepath.relative_path)
|
||||||
|
|
Loading…
Reference in a new issue