add regex to test if audio file names are correctly formated

This commit is contained in:
Tomasz Frątczak 2024-02-17 16:49:12 +01:00
parent 13ae7e5b57
commit 1fe049e065
2 changed files with 8 additions and 3 deletions

View File

@ -8,13 +8,13 @@ class Config:
password = None password = None
url = None url = None
path = None path = None
def parse_args(self): def parse_args(self):
parser = argparse.ArgumentParser(description='Process some integers.') parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--path', type=str, help='Path to config yaml file', dest='path') parser.add_argument('--path', type=str, help='Path to config yaml file', dest='path')
args = parser.parse_args() args = parser.parse_args()
return args return args
def load_config(self, path=None): def load_config(self, path=None):
if path is None: if path is None:
path = '.config.yaml' path = '.config.yaml'

View File

@ -1,6 +1,7 @@
import logging import logging
import time import time
import os import os
import re
from datetime import datetime from datetime import datetime
@ -33,11 +34,15 @@ class Picker:
if file_marker < marker: if file_marker < marker:
return file return file
def match_name(self, input):
pattern = r"^\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}\.m4a$"
return bool(re.match(pattern, input))
def list_files(self): def list_files(self):
files = [] files = []
for filename in os.listdir(self.directory): for filename in os.listdir(self.directory):
filepath = os.path.join(self.directory, filename) filepath = os.path.join(self.directory, filename)
if os.path.isfile(filepath) and filename.endswith(".m4a"): if os.path.isfile(filepath) and self.match_name(filename):
files.append(filepath) files.append(filepath)
return files return files