Skip to content

Commit

Permalink
Handle existing voices.json` file before writing new data
Browse files Browse the repository at this point in the history
- Remove existing `voices.json` file before writing new data to avoid
  conflicts.
  • Loading branch information
cr2007 committed Jun 15, 2024
1 parent 54d4317 commit d3cee34
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cambai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ def get_all_voices(self, write_to_file: bool = False) -> list[Optional[VoicesLis

# If write_to_file is True, write the response to a JSON file
if write_to_file:
# If the file already exists, remove it before writing the new data
if os.path.exists("voices.json"):
print("'voices.json' already exists.\n"
"Removing the existing file...")
os.remove("voices.json")

# Open the file in write mode
with open("voices.json", "w", encoding="utf-8") as file:
# Dump the JSON response into the file with indentation for readability
Expand Down

0 comments on commit d3cee34

Please sign in to comment.