From 1fe049e065b8820df0169f303517aea9f13d9ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Fr=C4=85tczak?= Date: Sat, 17 Feb 2024 16:49:12 +0100 Subject: [PATCH] add regex to test if audio file names are correctly formated --- notescriber/config.py | 4 ++-- notescriber/picker.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/notescriber/config.py b/notescriber/config.py index 58fc0d6..67685df 100644 --- a/notescriber/config.py +++ b/notescriber/config.py @@ -8,13 +8,13 @@ class Config: password = None url = None path = None - + def parse_args(self): parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--path', type=str, help='Path to config yaml file', dest='path') args = parser.parse_args() return args - + def load_config(self, path=None): if path is None: path = '.config.yaml' diff --git a/notescriber/picker.py b/notescriber/picker.py index 3123949..f253433 100644 --- a/notescriber/picker.py +++ b/notescriber/picker.py @@ -1,6 +1,7 @@ import logging import time import os +import re from datetime import datetime @@ -33,11 +34,15 @@ class Picker: if file_marker < marker: 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): files = [] for filename in os.listdir(self.directory): 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) return files