feat: add directory configuration
Signed-off-by: Konstantin Fickel <mail@konstantinfickel.de>
This commit is contained in:
parent
87be5c22a2
commit
ac9df7eb62
4 changed files with 108 additions and 5 deletions
|
|
@ -1,22 +1,21 @@
|
|||
import glob
|
||||
import os
|
||||
import typer # type: ignore [reportMissingImports]
|
||||
import click # type: ignore [reportMissingImports]
|
||||
import typer
|
||||
import click
|
||||
from shutil import move
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from streamer.parse.parse import parse_markdown_file
|
||||
from streamer.query.task import find_by_markers
|
||||
from streamer.settings import Settings
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
streamer_directory = os.getcwd()
|
||||
|
||||
|
||||
@app.command()
|
||||
def todo() -> None:
|
||||
for file_name in glob.glob(f"{glob.escape(streamer_directory)}/*.md"):
|
||||
for file_name in glob.glob(f"{glob.escape(Settings().base_folder)}/*.md"):
|
||||
with open(file_name, "r") as file:
|
||||
file_content = file.read()
|
||||
sharded_document = parse_markdown_file(file_name, file_content)
|
||||
|
|
@ -36,6 +35,8 @@ def todo() -> None:
|
|||
|
||||
@app.command()
|
||||
def new() -> None:
|
||||
streamer_directory = Settings().base_folder
|
||||
|
||||
timestamp = datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
preliminary_file_name = f"{timestamp}_wip.md"
|
||||
prelimary_path = os.path.join(streamer_directory, preliminary_file_name)
|
||||
|
|
|
|||
33
src/streamer/settings/__init__.py
Normal file
33
src/streamer/settings/__init__.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import os
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
PydanticBaseSettingsSource,
|
||||
SettingsConfigDict,
|
||||
YamlConfigSettingsSource,
|
||||
)
|
||||
from xdg_base_dirs import xdg_config_home
|
||||
|
||||
SETTINGS_FILE = xdg_config_home() / "streamer" / "config.yaml"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file_encoding="utf-8")
|
||||
|
||||
base_folder: str = os.getcwd()
|
||||
|
||||
@classmethod
|
||||
def settings_customise_sources(
|
||||
cls,
|
||||
settings_cls: type[BaseSettings],
|
||||
init_settings: PydanticBaseSettingsSource,
|
||||
env_settings: PydanticBaseSettingsSource,
|
||||
dotenv_settings: PydanticBaseSettingsSource,
|
||||
file_secret_settings: PydanticBaseSettingsSource,
|
||||
) -> tuple[PydanticBaseSettingsSource, ...]:
|
||||
return (
|
||||
init_settings,
|
||||
YamlConfigSettingsSource(settings_cls, yaml_file=SETTINGS_FILE),
|
||||
dotenv_settings,
|
||||
env_settings,
|
||||
file_secret_settings,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue