move more complex classes to their own module, keep imports helpers.py core python
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
@@ -8,8 +7,6 @@ from collections import OrderedDict
|
||||
from configparser import ConfigParser
|
||||
from itertools import chain
|
||||
|
||||
from tzlocal import get_localzone
|
||||
|
||||
_settings = None
|
||||
|
||||
DB_PATH = os.path.expanduser('~/BirdNET-Pi/scripts/birds.db')
|
||||
@@ -60,47 +57,6 @@ def get_settings(settings_path='/etc/birdnet/birdnet.conf', force_reload=False):
|
||||
return settings
|
||||
|
||||
|
||||
class Detection:
|
||||
def __init__(self, file_date, start_time, stop_time, scientific_name, common_name, confidence):
|
||||
self.start = float(start_time)
|
||||
self.stop = float(stop_time)
|
||||
self.datetime = file_date + datetime.timedelta(seconds=self.start)
|
||||
self.date = self.datetime.strftime("%Y-%m-%d")
|
||||
self.time = self.datetime.strftime("%H:%M:%S")
|
||||
self.iso8601 = self.datetime.astimezone(get_localzone()).isoformat()
|
||||
self.week = self.datetime.isocalendar()[1]
|
||||
self.confidence = round(float(confidence), 4)
|
||||
self.confidence_pct = round(self.confidence * 100)
|
||||
self.species = scientific_name
|
||||
self.scientific_name = scientific_name
|
||||
self.common_name = common_name
|
||||
self.common_name_safe = self.common_name.replace("'", "").replace(" ", "_")
|
||||
self.file_name_extr = None
|
||||
|
||||
|
||||
class ParseFileName:
|
||||
def __init__(self, file_name):
|
||||
self.file_name = file_name
|
||||
name = os.path.splitext(os.path.basename(file_name))[0]
|
||||
date_created = re.search('^[0-9]+-[0-9]+-[0-9]+', name).group()
|
||||
time_created = re.search('[0-9]+:[0-9]+:[0-9]+$', name).group()
|
||||
self.file_date = datetime.datetime.strptime(f'{date_created}T{time_created}', "%Y-%m-%dT%H:%M:%S")
|
||||
self.root = name
|
||||
|
||||
ident_match = re.search("RTSP_[0-9]+-", file_name)
|
||||
self.RTSP_id = ident_match.group() if ident_match is not None else ""
|
||||
|
||||
@property
|
||||
def iso8601(self):
|
||||
current_iso8601 = self.file_date.astimezone(get_localzone()).isoformat()
|
||||
return current_iso8601
|
||||
|
||||
@property
|
||||
def week(self):
|
||||
week = self.file_date.isocalendar()[1]
|
||||
return week
|
||||
|
||||
|
||||
def get_open_files_in_dir(dir_name):
|
||||
result = subprocess.run(['lsof', '-w', '-Fn', '+D', f'{dir_name}'], check=False, capture_output=True)
|
||||
ret = result.stdout.decode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user