adding test cases, adding logger
This commit is contained in:
parent
1b15792e00
commit
13ae7e5b57
|
@ -3,7 +3,7 @@
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python notescriber.py
|
python notescriber.py --path /path/to/data
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
|
@ -1,7 +1,23 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from notescriber import picker
|
# from notescriber import picker
|
||||||
|
# from notescriber import config
|
||||||
|
# from notescriber import dispatcher
|
||||||
|
# from notescriber import notetaker
|
||||||
|
# from notescriber import transcriber
|
||||||
|
|
||||||
|
import notescriber
|
||||||
|
import logging
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
config = notescriber.config.Config()
|
||||||
|
config.load_config(".config.yaml")
|
||||||
|
dispatcher = notescriber.dispatcher.Dispatcher()
|
||||||
|
notetaker = notescriber.notetaker.Notetaker(config.username,config.password, config.url)
|
||||||
|
picker = notescriber.picker.Picker(config.path, dispatcher)
|
||||||
|
transcriber = notescriber.transcriber.Transcriber()
|
||||||
|
|
||||||
|
dispatcher.add_note_generator(notetaker)
|
||||||
|
dispatcher.add_audio_processor(transcriber)
|
||||||
|
|
||||||
picker.observe()
|
picker.observe()
|
|
@ -4,13 +4,16 @@ 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
|
||||||
|
import logging
|
||||||
|
|
||||||
config = config.Config()
|
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
|
||||||
config.load_config(".config.yaml")
|
|
||||||
dispatcher = dispatcher.Dispatcher()
|
|
||||||
notetaker = notetaker.Notetaker(config.username,config.password, config.url)
|
|
||||||
picker = picker.Picker(config.path, dispatcher)
|
|
||||||
transcriber = transcriber.Transcriber()
|
|
||||||
|
|
||||||
dispatcher.add_note_generator(notetaker)
|
# config = config.Config()
|
||||||
dispatcher.add_audio_processor(transcriber)
|
# config.load_config(".config.yaml")
|
||||||
|
# dispatcher = dispatcher.Dispatcher()
|
||||||
|
# notetaker = notetaker.Notetaker(config.username,config.password, config.url)
|
||||||
|
# picker = picker.Picker(config.path, dispatcher)
|
||||||
|
# transcriber = transcriber.Transcriber()
|
||||||
|
|
||||||
|
# dispatcher.add_note_generator(notetaker)
|
||||||
|
# dispatcher.add_audio_processor(transcriber)
|
|
@ -1,4 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -24,4 +25,4 @@ class Config:
|
||||||
self.path = self.parse_args().path
|
self.path = self.parse_args().path
|
||||||
if self.path is None:
|
if self.path is None:
|
||||||
self.path = confFile['path']
|
self.path = confFile['path']
|
||||||
print(self.path)
|
logging.info(f"Loaded config from {path}")
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -7,7 +8,6 @@ class Picker:
|
||||||
|
|
||||||
directory = None
|
directory = None
|
||||||
dispatcher = None
|
dispatcher = None
|
||||||
observer = None
|
|
||||||
last_file_marker = None
|
last_file_marker = None
|
||||||
|
|
||||||
def __init__(self, directory, dispatcher):
|
def __init__(self, directory, dispatcher):
|
||||||
|
@ -33,14 +33,6 @@ class Picker:
|
||||||
if file_marker < marker:
|
if file_marker < marker:
|
||||||
return file
|
return file
|
||||||
|
|
||||||
|
|
||||||
def identify_time_window(self, file_time):
|
|
||||||
if self.last_file_time is None:
|
|
||||||
self.last_file_time = time.time()
|
|
||||||
if file_time > self.last_file_time:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def list_files(self):
|
def list_files(self):
|
||||||
files = []
|
files = []
|
||||||
for filename in os.listdir(self.directory):
|
for filename in os.listdir(self.directory):
|
||||||
|
@ -50,6 +42,7 @@ class Picker:
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def observe(self):
|
def observe(self):
|
||||||
|
logging.info(f"Watching directory: {self.directory}")
|
||||||
while True:
|
while True:
|
||||||
file_marker = self.read_last_file_marker()
|
file_marker = self.read_last_file_marker()
|
||||||
files = self.list_files()
|
files = self.list_files()
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import whisper
|
import whisper
|
||||||
|
import logging
|
||||||
|
|
||||||
class Transcriber:
|
class Transcriber:
|
||||||
|
|
||||||
|
@ -8,6 +9,6 @@ class Transcriber:
|
||||||
self.model = whisper.load_model("base")
|
self.model = whisper.load_model("base")
|
||||||
|
|
||||||
def execute(self, audio_file):
|
def execute(self, audio_file):
|
||||||
print("Transcribing audio file: " + audio_file)
|
logging.info(f"Transcribing audio file: {audio_file}")
|
||||||
result = self.model.transcribe(audio_file)
|
result = self.model.transcribe(audio_file)
|
||||||
return result['text']
|
return result['text']
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import unittest
|
# import unittest
|
||||||
from notescriber.config import Config
|
# from notescriber.config import Config
|
||||||
|
|
||||||
class TranscriptorTest(unittest.TestCase):
|
# class TranscriptorTest(unittest.TestCase):
|
||||||
def setUp(self):
|
# def setUp(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def tearDown(self):
|
# def tearDown(self):
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
def test_run(self):
|
# def test_run(self):
|
||||||
cfg = Config()
|
# cfg = Config()
|
||||||
cfg.load_config(path="example.config.yaml")
|
# cfg.load_config(path="example.config.yaml")
|
||||||
self.assertEqual("username", cfg.username)
|
# self.assertEqual("username", cfg.username)
|
||||||
self.assertEqual("password", cfg.password)
|
# self.assertEqual("password", cfg.password)
|
||||||
self.assertEqual("url.org", cfg.url)
|
# self.assertEqual("url.org", cfg.url)
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
import unittest
|
||||||
|
from notescriber.picker import Picker
|
||||||
|
|
||||||
|
class FakeDispatcher:
|
||||||
|
def process_audio_file(filename):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class TranscriptorTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_constructor(self):
|
||||||
|
directory = "/data"
|
||||||
|
dispatcher = FakeDispatcher()
|
||||||
|
picker = Picker(directory, dispatcher)
|
||||||
|
self.assertEqual(directory, picker.directory)
|
||||||
|
self.assertEqual(dispatcher, picker.dispatcher)
|
||||||
|
|
||||||
|
def test_read_file_marker(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_update_last_file_marker(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def find_next_file(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_list_files(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def test_observe(self):
|
||||||
|
pass
|
Loading…
Reference in New Issue