From 7fc073ed19600d2a780980303488280732b5a49d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Mon, 12 Feb 2024 00:18:09 +0100 Subject: [PATCH] Create basic app skeleton around pyinotify --- .gitignore | 9 ++++++++- README.md | 19 +++++++++++++++++++ makefile | 15 +++++++++++++++ notescriber.py | 9 +++++++++ notescriber/__init__.py | 4 ++++ notescriber/notetaker.py | 0 notescriber/picker.py | 34 ++++++++++++++++++++++++++++++++++ notescriber/transcriber.py | 6 ++++++ pyproject.toml | 22 ++++++++++++++++++++++ requirements.txt | 2 ++ 10 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 makefile create mode 100755 notescriber.py create mode 100644 notescriber/__init__.py create mode 100644 notescriber/notetaker.py create mode 100644 notescriber/picker.py create mode 100644 notescriber/transcriber.py create mode 100644 pyproject.toml create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 5d381cc..330e4bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -# ---> Python # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -9,13 +8,17 @@ __pycache__/ # Distribution / packaging .Python +bin/ build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ +include +include/ lib/ +lib64 lib64/ parts/ sdist/ @@ -128,6 +131,7 @@ venv/ ENV/ env.bak/ venv.bak/ +pyvenv.cfg # Spyder project settings .spyderproject @@ -160,3 +164,6 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +# Database +data +data/ \ No newline at end of file diff --git a/README.md b/README.md index 5839292..e30a556 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ # notescriber +## Usage + +```bash +python notescriber.py +``` + +## Testing +Set up virtual environment: +```bash +python -m venv . +source bin/activate +make bootstrap +make test +``` + +Run tests: +```bash +make test +``` \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..6ee301a --- /dev/null +++ b/makefile @@ -0,0 +1,15 @@ +# Makefile + +# Command to run the tests +TEST_CMD = python -m unittest discover -s tests -p "*_test.py" + +# Target to run the tests +test: + @echo "Running tests..." + @$(TEST_CMD) + +bootstrap: + python -m pip install -r requirements.txt + +# Default target +default: test diff --git a/notescriber.py b/notescriber.py new file mode 100755 index 0000000..8507352 --- /dev/null +++ b/notescriber.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +from notescriber.transcriber import Transcriber +from notescriber.picker import Picker + +if __name__ == '__main__': + transcriber = Transcriber() + picker = Picker("/home/octopusx/Code/test", transcriber) + picker.observe() \ No newline at end of file diff --git a/notescriber/__init__.py b/notescriber/__init__.py new file mode 100644 index 0000000..75a5d00 --- /dev/null +++ b/notescriber/__init__.py @@ -0,0 +1,4 @@ +#!/usr/bin/env python3 +from notescriber import notetaker +from notescriber import picker +from notescriber import transcriber diff --git a/notescriber/notetaker.py b/notescriber/notetaker.py new file mode 100644 index 0000000..e69de29 diff --git a/notescriber/picker.py b/notescriber/picker.py new file mode 100644 index 0000000..d08f1c7 --- /dev/null +++ b/notescriber/picker.py @@ -0,0 +1,34 @@ +import pyinotify + +class EventHandler(pyinotify.ProcessEvent): + def process_IN_CREATE(self, event): + print(f'New file: {event.pathname}') + return event.pathname + +class Picker: + + directory = None + callbackObject = None + + def __init__(self, directory, callbackObject): + self.directory = directory + self.callbackObject = callbackObject + + def observe(self): + wm = pyinotify.WatchManager() + notifier = pyinotify.Notifier(wm, EventHandler()) + wm.add_watch(self.directory, pyinotify.IN_CREATE, self.callbackObject.execute) + + print(f'Watching {self.directory} for changes...') + notifier.loop() + +# def observe_directory(directory): +# wm = pyinotify.WatchManager() +# notifier = pyinotify.Notifier(wm, EventHandler()) +# wm.add_watch(directory, pyinotify.IN_CREATE) + +# print(f'Watching {directory} for changes...') +# notifier.loop() + +# Use the function +# observe_directory('/home/octopusx/Code/test') diff --git a/notescriber/transcriber.py b/notescriber/transcriber.py new file mode 100644 index 0000000..7da498e --- /dev/null +++ b/notescriber/transcriber.py @@ -0,0 +1,6 @@ +class Transcriber: + def __init__(self): + pass + + def execute(self, audio_file): + print("Transcribing audio file: " + audio_file.pathname) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d7e2c3c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "notescriber" +version = "0.0.1" +authors = [ + { name="Tomasz FrÄ…tczak", email="accidentallycompetent@octopusx.de" }, +] +description = "Watches a directory for new files, then triggers OpenAI whisper transcription service to convert voice notes into text notes in NextCloud." +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.urls] +Homepage = "https://teapot.octopusx.de/accidentallycompetent/notescriber" +Issues = "https://teapot.octopusx.de/accidentallycompetent/notescriber/issues" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..4ba2ae9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +whisper==1.1.10 +pyinotify==0.9.6 \ No newline at end of file