Resolve merge conflicts
This commit is contained in:
BIN
libs/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
libs/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
libs/__pycache__/filesearch.cpython-314.pyc
Normal file
BIN
libs/__pycache__/filesearch.cpython-314.pyc
Normal file
Binary file not shown.
BIN
libs/__pycache__/hashd.cpython-314.pyc
Normal file
BIN
libs/__pycache__/hashd.cpython-314.pyc
Normal file
Binary file not shown.
@@ -1,27 +1,47 @@
|
|||||||
import time
|
from queue import Queue, Empty
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Generator, Optional
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
from pathlib import Path
|
|
||||||
downloads_path = Path.home() / "Downloads"
|
|
||||||
|
|
||||||
class NewFileHandler(FileSystemEventHandler):
|
|
||||||
|
class _NewFileHandler(FileSystemEventHandler):
|
||||||
|
def __init__(self, queue: Queue):
|
||||||
|
super().__init__()
|
||||||
|
self.queue = queue
|
||||||
|
|
||||||
def on_created(self, event):
|
def on_created(self, event):
|
||||||
if not event.is_directory:
|
if not event.is_directory:
|
||||||
print(f"New file detected: {event.src_path}")
|
self.queue.put(Path(event.src_path))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
path_to_watch = downloads_path
|
def watch_downloads(
|
||||||
|
path: Optional[Path] = None,
|
||||||
event_handler = NewFileHandler()
|
poll_interval: float = 0.5,
|
||||||
|
) -> Generator[Path, None, None]:
|
||||||
|
"""
|
||||||
|
Yields the Path object of each newly detected file as soon as it is created.
|
||||||
|
|
||||||
|
:param path: Path object or string of the directory to watch. Defaults to ~/Downloads.
|
||||||
|
:param poll_interval: Timeout in seconds for checking events (allows clean exit on Ctrl+C).
|
||||||
|
"""
|
||||||
|
target_path = Path(path) if path else (Path.home() / "Downloads")
|
||||||
|
file_queue: Queue = Queue()
|
||||||
|
|
||||||
|
handler = _NewFileHandler(file_queue)
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(event_handler, path=path_to_watch, recursive=False)
|
observer.schedule(handler, path=str(target_path), recursive=False)
|
||||||
|
|
||||||
print(f"Monitoring folder: {path_to_watch}...")
|
|
||||||
observer.start()
|
observer.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
time.sleep(1)
|
try:
|
||||||
|
file_path = file_queue.get(timeout=poll_interval)
|
||||||
|
yield file_path
|
||||||
|
except Empty:
|
||||||
|
continue
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
observer.stop()
|
observer.stop()
|
||||||
observer.join()
|
observer.join()
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import hashlib
|
|
||||||
|
|
||||||
def hashcheck(fileToCheck):
|
|
||||||
with open(fileToCheck, "rb") as f:
|
|
||||||
digest = hashlib.file_digest(f, "sha256")
|
|
||||||
file_hash = digest.hexdigest()
|
|
||||||
print(file_hash)
|
|
||||||
|
|
||||||
hashcheck("ha.txt")
|
|
||||||
|
|
||||||
|
|
||||||
32
libs/hashd.py
Normal file
32
libs/hashd.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Anchor hashes.txt relative to the libs folder
|
||||||
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
HASH_LIST_PATH = os.path.join(
|
||||||
|
BASE_DIR, "hashes.txt"
|
||||||
|
) # or os.path.join(BASE_DIR, "..", "hashes.txt")
|
||||||
|
|
||||||
|
|
||||||
|
def hashcheck(fileToCheck):
|
||||||
|
# Remove trailing spaces or wrapped quotes from drag-and-drop
|
||||||
|
clean_path = str(fileToCheck).strip().strip('"').strip("'")
|
||||||
|
|
||||||
|
if not os.path.isfile(clean_path):
|
||||||
|
print(f"Error: Path does not exist or is a directory: {clean_path}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
# Read file in binary mode and compute hash
|
||||||
|
with open(clean_path, "rb") as f:
|
||||||
|
digest = hashlib.file_digest(f, "sha256")
|
||||||
|
file_hash = digest.hexdigest()
|
||||||
|
|
||||||
|
print(f"File Hash: {file_hash}")
|
||||||
|
|
||||||
|
if not os.path.exists(HASH_LIST_PATH):
|
||||||
|
print(f"Error: Hash reference list missing at {HASH_LIST_PATH}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
with open(HASH_LIST_PATH, "r", encoding="utf-8") as file:
|
||||||
|
content = file.read()
|
||||||
|
return file_hash.lower() in content.lower()
|
||||||
23140
libs/hashes.txt
Normal file
23140
libs/hashes.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user