basic working config loader

This commit is contained in:
Tomasz Frątczak 2024-02-13 23:45:16 +01:00
parent 0d0750fa96
commit 53102be98b
8 changed files with 63 additions and 8 deletions

5
.gitignore vendored
View File

@ -170,4 +170,7 @@ data/
# openai-whisper # openai-whisper
share share
share/ share/
# local config
.config.yaml

3
example.config.yaml Normal file
View File

@ -0,0 +1,3 @@
username: "username"
password: "password"
url: "url.org"

View File

@ -1,12 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from notescriber import config
from notescriber import dispatcher from notescriber import dispatcher
from notescriber import notetaker from notescriber import notetaker
from notescriber import picker from notescriber import picker
from notescriber import transcriber from notescriber import transcriber
config = config.Config()
config.load_config(".config.yaml")
dispatcher = dispatcher.Dispatcher() dispatcher = dispatcher.Dispatcher()
notetaker = notetaker.Notetaker() notetaker = notetaker.Notetaker(config.username,config.password, config.url)
picker = picker.Picker("/home/octopusx/Code/test",dispatcher) picker = picker.Picker(config.path, dispatcher)
transcriber = transcriber.Transcriber() transcriber = transcriber.Transcriber()
dispatcher.add_note_generator(notetaker) dispatcher.add_note_generator(notetaker)

View File

@ -0,0 +1,27 @@
import argparse
import yaml
class Config:
username = None
password = None
url = None
path = None
def __init__(self):
pass
def parse_args(self):
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--path', type=str, help='Path to config yaml file')
args = parser.parse_args()
return args.arg
def load_config(self, path=None):
if path is None:
path = '.config.yaml'
confFile = yaml.safe_load(open(path))
self.username = confFile['username']
self.password = confFile['password']
self.url = confFile['url']
self.path = confFile['path']

View File

@ -4,12 +4,14 @@ class Notetaker:
username = None username = None
password = None password = None
url = None
def __init__(self, username, password): def __init__(self, username, password, url):
self.username = username self.username = username
self.password = password self.password = password
self.url = url
def generate_note(self, filename, note): def generate_note(self, filename, note):
api = NotesApi(self.username, self.password, 'cloud.octopusx.de') api = NotesApi(self.username, self.password, self.url)
ncnote = Note(title=filename, content=note, category="Voicenotes") ncnote = Note(title=filename, content=note, category="Voicenotes")
api.create_note(ncnote) api.create_note(ncnote)

View File

@ -1,3 +1,4 @@
openai-whisper==20231117 openai-whisper==20231117
pyinotify==0.9.6 pyinotify==0.9.6
nextcloud_notes_api==1.0.0 nextcloud_notes_api==1.0.0
PyYaml==6.0.1

16
tests/config_test.py Normal file
View File

@ -0,0 +1,16 @@
import unittest
from notescriber.config import Config
class TranscriptorTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_run(self):
cfg = Config()
cfg.load_config(path="example.config.yaml")
self.assertEqual("username", cfg.username)
self.assertEqual("password", cfg.password)
self.assertEqual("url.org", cfg.url)

View File

@ -9,6 +9,6 @@ class TranscriptorTest(unittest.TestCase):
pass pass
def test_run(self): def test_run(self):
ntk = Notetaker() ntk = Notetaker("title","content", "url")
ntk.generate_note("Test Note Title","This is my note") # ntk.generate_note("Test Note Title","This is my note")
self.assertEqual(True, True) self.assertEqual(True, True)