From 6eb24e74eb98ddb5e6a0cec484c51d25ce325ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Wed, 14 Feb 2024 21:20:20 +0100 Subject: [PATCH] Create a working docker setup --- dockerfile | 10 ++++++++++ notescriber/config.py | 12 ++++++------ notescriber/dispatcher.py | 9 ++++----- notescriber/notetaker.py | 9 ++++++++- requirements.txt | 3 ++- 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 dockerfile diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..7a29207 --- /dev/null +++ b/dockerfile @@ -0,0 +1,10 @@ +FROM python + +RUN mkdir /app +COPY notescriber /app/notescriber +COPY notescriber.py /app/notescriber.py +COPY requirements.txt /app/requirements.txt +COPY .config.yaml /app/.config.yaml +WORKDIR /app + +RUN pip install -r requirements.txt \ No newline at end of file diff --git a/notescriber/config.py b/notescriber/config.py index 6f2247a..61fcd5e 100644 --- a/notescriber/config.py +++ b/notescriber/config.py @@ -7,15 +7,12 @@ class Config: 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') + parser.add_argument('--path', type=str, help='Path to config yaml file', dest='path') args = parser.parse_args() - return args.arg + return args def load_config(self, path=None): if path is None: @@ -24,4 +21,7 @@ class Config: self.username = confFile['username'] self.password = confFile['password'] self.url = confFile['url'] - self.path = confFile['path'] \ No newline at end of file + self.path = self.parse_args().path + if self.path is None: + self.path = confFile['path'] + print(self.path) \ No newline at end of file diff --git a/notescriber/dispatcher.py b/notescriber/dispatcher.py index 15934b8..dbc0496 100644 --- a/notescriber/dispatcher.py +++ b/notescriber/dispatcher.py @@ -1,4 +1,5 @@ import threading +import os class Dispatcher: @@ -7,9 +8,6 @@ class Dispatcher: extensionFilter = None noteGenerator = None - def __init__(self): - pass - def add_audio_processor(self, audioProcessor): self.audioProcessor = audioProcessor @@ -19,11 +17,12 @@ class Dispatcher: def process_audio_file(self, audio_file): self.threads.append(threading.Thread(target=self._execute_thread, args=(audio_file,))) self.threads[-1].start() - # TODO: we need to have a way to wipe old threads, otherwise we will have a memory leak + # TODO: we need to have a way to wipe old threads, otherwise we may have a memory leak def _execute_thread(self, audio_file): + filename = os.path.basename(audio_file.pathname) note = self.audioProcessor.execute(audio_file.pathname) - self.noteGenerator.generate_note(audio_file.pathname, note) + self.noteGenerator.generate_note(filename, note) def halt(self): for thread in self.threads: diff --git a/notescriber/notetaker.py b/notescriber/notetaker.py index f0274de..03a8653 100644 --- a/notescriber/notetaker.py +++ b/notescriber/notetaker.py @@ -1,4 +1,5 @@ from nextcloud_notes_api import NotesApi, Note +from datetime import date class Notetaker: @@ -11,7 +12,13 @@ class Notetaker: self.password = password self.url = url + def format_note(self, filename, note): + result = f"# {filename}\n\n" + result += f"-----------------\nTranscription date: {date.today()}\n-----------------\n\n" + result += note + return result + def generate_note(self, filename, note): api = NotesApi(self.username, self.password, self.url) - ncnote = Note(title=filename, content=note, category="Voicenotes") + ncnote = Note(title=filename, content=self.format_note(filename, note), category="Voicenotes") api.create_note(ncnote) diff --git a/requirements.txt b/requirements.txt index e3b06ad..7ebb91d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ openai-whisper==20231117 pyinotify==0.9.6 nextcloud_notes_api==1.0.0 -PyYaml==6.0.1 \ No newline at end of file +PyYaml==6.0.1 +pyasyncore==1.0.3 \ No newline at end of file