Refactor book title stripping into function
This commit is contained in:
parent
d301a61e92
commit
71cf84443d
1 changed files with 5 additions and 2 deletions
|
@ -20,10 +20,9 @@ def main(fpath, db):
|
||||||
|
|
||||||
csv = csv.DictReader(f)
|
csv = csv.DictReader(f)
|
||||||
|
|
||||||
title_strip_pattern = re.compile(r"([^\s\w]|_)+")
|
|
||||||
note_file = ""
|
note_file = ""
|
||||||
for row in csv:
|
for row in csv:
|
||||||
title_stripped = title_strip_pattern.sub("", row["Title"])
|
title_stripped = strip_book_title(row["Title"])
|
||||||
|
|
||||||
# switch to next book
|
# switch to next book
|
||||||
if not is_same_book(row["Title"]):
|
if not is_same_book(row["Title"]):
|
||||||
|
@ -96,6 +95,10 @@ def write_to_files(notes):
|
||||||
num_added += 1
|
num_added += 1
|
||||||
print(f"Added {num_added} entries to it.")
|
print(f"Added {num_added} entries to it.")
|
||||||
|
|
||||||
|
title_strip_pattern = re.compile(r"([^\s\w]|_)+")
|
||||||
|
def strip_book_title(title) -> str:
|
||||||
|
return title_strip_pattern.sub("", title)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use argument passed to command as file or default file here
|
# use argument passed to command as file or default file here
|
||||||
|
|
Loading…
Reference in a new issue