-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
functions/__pycache__/add_footer.cpython-311.pyc | ||
functions/__pycache__/clean_text.cpython-311.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def add_footer(output_file_path): | ||
with open('footer.txt', 'r', encoding='utf-8') as file: | ||
footer = file.readlines() | ||
with open(output_file_path, 'r', encoding='utf-8') as file: | ||
lines = file.readlines() | ||
with open(output_file_path, 'w', encoding='utf-8') as file: | ||
file.writelines(footer) | ||
file.writelines(lines) | ||
print(f'Footer added to {output_file_path}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import re | ||
|
||
def clean_text(input_file_path, output_file_path): | ||
with open(input_file_path, 'r', encoding='utf-8') as file: | ||
lines = file.readlines() | ||
|
||
with open('remove.txt', 'r', encoding='utf-8') as file: | ||
remove_lines = file.readlines() | ||
replace_rules = {} | ||
for line in remove_lines: | ||
if ':' in line: | ||
remove_str, replace_str = line.strip().split(':', 1) | ||
replace_rules[remove_str] = replace_str.strip() | ||
|
||
cleaned_lines = [] | ||
for line in lines: | ||
if not line.strip() == '----': | ||
line = line.strip() | ||
is_dialog = line.lstrip().startswith('d') | ||
if is_dialog: | ||
line = re.sub(r'd\d{2}:\d{2}', '', line) | ||
for remove_str, replace_str in replace_rules.items(): | ||
if remove_str in line: | ||
line = line.replace(remove_str, replace_str + " ") | ||
else: | ||
line = re.sub(r'\b\d{2}:\d{2}\b', '', line) | ||
for remove_str in replace_rules: | ||
if remove_str in line: | ||
line = line.replace(remove_str, '') | ||
line = ' '.join(line.split()) | ||
if line.strip(): | ||
cleaned_lines.append(line + '\n') | ||
|
||
with open(output_file_path, 'w', encoding='utf-8') as file: | ||
file.writelines(cleaned_lines) | ||
print(f'Cleaned text saved to {output_file_path}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters