-
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
1 parent
bdc07e4
commit 1c37119
Showing
3 changed files
with
108 additions
and
51 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,48 @@ | ||
from dataclasses import dataclass | ||
import json | ||
from pathlib import Path | ||
import typer | ||
|
||
APP_NAME = "obs3dian" | ||
SETUP_FILE_NAME = "config.json" | ||
APP_DIR_PATH = typer.get_app_dir(APP_NAME) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class Configuration: | ||
profile_name: str = "" | ||
aws_access_key: str = "" | ||
aws_secret_key: str = "" | ||
bucket_name: str = "obs3dian" | ||
output_folder_path: str = "./output" | ||
image_folder_path: str = "./images" | ||
|
||
|
||
def load_configs() -> Configuration: | ||
""" | ||
Load config json file from app dir | ||
Returns: | ||
dict: config json | ||
""" | ||
|
||
try: | ||
config_path = Path(APP_DIR_PATH) / SETUP_FILE_NAME | ||
with config_path.open("r") as f: | ||
configs = json.load(f) | ||
|
||
return Configuration(**configs) | ||
|
||
except FileNotFoundError as e: | ||
print("Config file is not founded... input your configuration\n") | ||
raise e | ||
|
||
|
||
def save_config(json_data: dict): | ||
app_dir_path = Path(APP_DIR_PATH) # create app setting folder | ||
if not app_dir_path.exists(): | ||
app_dir_path.mkdir() | ||
|
||
config_path = app_dir_path / SETUP_FILE_NAME | ||
with config_path.open("w") as f: | ||
json.dump(json_data, f) # write config.json |
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
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