Skip to content

Commit

Permalink
adds settings that i forgot to add
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed May 10, 2023
1 parent 152517c commit 9d2e20b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/video_subtitles/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Reads and writes settings to a json file.
"""

import json
import os

HERE = os.path.dirname(os.path.abspath(__file__))

SETTINGS_JSON = os.path.join(HERE, "settings.json")


class Settings:
"""Settings class."""

def __init__(self) -> None:
self.data: dict[str, str | int | dict] = {}
self.load()

def deepl_key(self) -> str | None:
"""Return the DeepL API key."""
return self.data.get("deepl_key", None) # type: ignore

def set_deepl_key(self, key: str) -> None:
"""Set the DeepL API key."""
self.data["deepl_key"] = key

def save(self) -> None:
"""Save the settings."""
# dump json to file
with open(SETTINGS_JSON, encoding="utf-8", mode="w") as f:
json.dump(self.data, f, indent=4)

def load(self) -> None:
"""Load the settings."""
# load json from file
if not os.path.exists(SETTINGS_JSON):
self.data = {}
return
with open(SETTINGS_JSON, encoding="utf-8", mode="r") as f:
self.data = json.load(f)

0 comments on commit 9d2e20b

Please sign in to comment.