mirror of
https://github.com/tanrax/notion-to-joplin.git
synced 2024-11-21 12:35:41 +01:00
Merge pull request #1 from Meisenburger13/Meisenburger13-encoding
This commit is contained in:
commit
5c1199f315
@ -49,7 +49,7 @@ print("Renaming files and fixing links...")
|
|||||||
path_to_files = path.join(FOLDER_EXTRACTION, "**/*." + MARKDOWN_EXTENSION)
|
path_to_files = path.join(FOLDER_EXTRACTION, "**/*." + MARKDOWN_EXTENSION)
|
||||||
for filename in glob.iglob(path_to_files, recursive=True):
|
for filename in glob.iglob(path_to_files, recursive=True):
|
||||||
# Get the heading of the file
|
# Get the heading of the file
|
||||||
with open(filename, "r") as file:
|
with open(filename, "r", encoding="utf-8") as file:
|
||||||
# Get the heading
|
# Get the heading
|
||||||
first_line = file.readline()
|
first_line = file.readline()
|
||||||
heading = first_line.replace("# ", "").replace("\n", "").replace("/", "-")
|
heading = first_line.replace("# ", "").replace("\n", "").replace("/", "-")
|
||||||
@ -57,7 +57,7 @@ for filename in glob.iglob(path_to_files, recursive=True):
|
|||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
lines_without_heading = lines[1:]
|
lines_without_heading = lines[1:]
|
||||||
# Write the file without the heading
|
# Write the file without the heading
|
||||||
with open(filename, "w") as file:
|
with open(filename, "w", encoding="utf-8") as file:
|
||||||
file.write("".join(lines_without_heading))
|
file.write("".join(lines_without_heading))
|
||||||
# Rename the file
|
# Rename the file
|
||||||
new_filename = path.join(path.dirname(filename), heading + "." + MARKDOWN_EXTENSION)
|
new_filename = path.join(path.dirname(filename), heading + "." + MARKDOWN_EXTENSION)
|
||||||
@ -66,9 +66,9 @@ for filename in glob.iglob(path_to_files, recursive=True):
|
|||||||
old_filename_encoded = urllib.parse.quote(ntpath.basename(filename))
|
old_filename_encoded = urllib.parse.quote(ntpath.basename(filename))
|
||||||
heading_encoded = urllib.parse.quote(heading) + "." + MARKDOWN_EXTENSION
|
heading_encoded = urllib.parse.quote(heading) + "." + MARKDOWN_EXTENSION
|
||||||
for filename_to_fix in glob.iglob(path_to_files, recursive=True):
|
for filename_to_fix in glob.iglob(path_to_files, recursive=True):
|
||||||
with open(filename_to_fix, "r") as file:
|
with open(filename_to_fix, "r", encoding="utf-8") as file:
|
||||||
lines_to_fix = file.readlines()
|
lines_to_fix = file.readlines()
|
||||||
with open(filename_to_fix, "w") as file:
|
with open(filename_to_fix, "w", encoding="utf-8") as file:
|
||||||
text_to_write = "".join(lines_to_fix).replace(
|
text_to_write = "".join(lines_to_fix).replace(
|
||||||
old_filename_encoded, heading_encoded
|
old_filename_encoded, heading_encoded
|
||||||
)
|
)
|
||||||
@ -87,9 +87,9 @@ for folder in glob.iglob(path_of_folders, recursive=True):
|
|||||||
old_folder_name_encoded = urllib.parse.quote(current_folder_name)
|
old_folder_name_encoded = urllib.parse.quote(current_folder_name)
|
||||||
new_folder_name_encoded = urllib.parse.quote(new_folder_name)
|
new_folder_name_encoded = urllib.parse.quote(new_folder_name)
|
||||||
for filename_to_fix in glob.iglob(path_to_files, recursive=True):
|
for filename_to_fix in glob.iglob(path_to_files, recursive=True):
|
||||||
with open(filename_to_fix, "r") as file:
|
with open(filename_to_fix, "r", encoding="utf-8") as file:
|
||||||
lines_to_fix = file.readlines()
|
lines_to_fix = file.readlines()
|
||||||
with open(filename_to_fix, "w") as file:
|
with open(filename_to_fix, "w", encoding="utf-8") as file:
|
||||||
text_to_write = "".join(lines_to_fix).replace(
|
text_to_write = "".join(lines_to_fix).replace(
|
||||||
old_folder_name_encoded, new_folder_name_encoded
|
old_folder_name_encoded, new_folder_name_encoded
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user