-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Now uses watchdog instead of custom solution - Added watchdog to requirements.txt - Added requirements_no_models.txt (faster to install packages if you already have the model installed) - Remove old filewatcher.py
- Loading branch information
1 parent
3e9422d
commit 05b8e40
Showing
5 changed files
with
71 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# directory_watcher.py | ||
import threading | ||
from watchdog.observers import Observer | ||
from watchdog.events import FileSystemEventHandler | ||
|
||
class DirectoryWatcher: | ||
def __init__(self, directory, callback): | ||
self.directory = directory | ||
self.callback = callback | ||
self.is_watching = True | ||
self.event_handler = FileSystemEventHandler() | ||
self.event_handler.on_created = self.on_created | ||
self.observer = Observer() | ||
self.observer.schedule(self.event_handler, path=self.directory, recursive=False) | ||
|
||
def on_created(self, event): | ||
if event.is_directory: | ||
return | ||
# Call your callback method here | ||
self.callback(event.src_path) | ||
|
||
def start_watching(self): | ||
# Define a thread target function | ||
def run_observer(): | ||
self.observer.start() | ||
try: | ||
while self.is_watching: | ||
pass | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
self.stop_watching() | ||
|
||
# Create and start the thread | ||
watcher_thread = threading.Thread(target=run_observer) | ||
watcher_thread.start() | ||
|
||
# Return the thread in case you want to manage it externally | ||
return watcher_thread | ||
|
||
def stop_watching(self): | ||
self.is_watching = False | ||
self.observer.stop() | ||
self.observer.join() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ pytest-cov==3.0.0 | |
langdetect==1.0.9 | ||
httpx | ||
fuzzywuzzy | ||
watchdog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fastapi==0.103.2 | ||
setuptools==68.2.0 | ||
wheel==0.41.2 | ||
spacy>=3.7.0, <3.8.0 | ||
uvicorn==0.23.2 | ||
levenshtein | ||
pytest==7.4.2 | ||
pytest_sugar==0.9.7 | ||
pytest-asyncio==0.21.1 | ||
pytest-cov==3.0.0 | ||
langdetect==1.0.9 | ||
httpx | ||
fuzzywuzzy | ||
watchdog |