From 7c350fcb852c4c3ec29c9edde7a763000b7491a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 16 Sep 2021 22:46:31 +0200 Subject: [PATCH] move regex for parsing lecture title into config file --- scripts/config.py | 3 ++- scripts/lectures.py | 9 ++++----- scripts/notes.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 15a07d0..e1eb48b 100644 --- a/scripts/config.py +++ b/scripts/config.py @@ -19,4 +19,5 @@ DEFAULT_MASTER_FILE_NAME = 'master.tex' MAX_LEN = 40 LECTURE_START_MARKER = 'start lectures' LECTURE_END_MARKER = 'end lectures' -DEFAULT_NEW_LECTURE_HEADER = r'\lecture{{{number}}}{{{date}}}{{}}' +DEFAULT_NEW_LECTURE_HEADER = r'\lecture{{{number}}}{{{date}}}{{{title}}}' +DEFAULT_LECTURE_SEARCH_REGEX = r'lecture{(.*?)}{(.*?)}{(.*)}' diff --git a/scripts/lectures.py b/scripts/lectures.py index 280e156..eb73861 100755 --- a/scripts/lectures.py +++ b/scripts/lectures.py @@ -1,12 +1,11 @@ #!/usr/bin/python3 -from pathlib import Path, PurePath -import os import locale +import os import re import subprocess from datetime import datetime -from config import DATE_FORMAT, LOCALE, DEFAULT_MASTER_FILE_NAME, DEFAULT_NEW_LECTURE_HEADER +from config import DATE_FORMAT, LOCALE, DEFAULT_NEW_LECTURE_HEADER, DEFAULT_LECTURE_SEARCH_REGEX from utils import get_week # TODO @@ -25,7 +24,7 @@ class Lecture: def __init__(self, file_path, course): with file_path.open() as f: for line in f: - lecture_match = re.search(r'lecture{(.*?)}{(.*?)}{(.*)}', line) + lecture_match = re.search(DEFAULT_LECTURE_SEARCH_REGEX, line) if lecture_match: break @@ -112,7 +111,7 @@ class Lectures(list): date = today.strftime(DATE_FORMAT) vimtex_root_str = f"%! TEX root = {str(os.path.relpath(self.notes.master_file, self.root))}\n" - header_str = DEFAULT_NEW_LECTURE_HEADER.format(number=new_lecture_number, date=date) + header_str = DEFAULT_NEW_LECTURE_HEADER.format(number=new_lecture_number, date=date, title='Untitled') new_lecture_path.touch() new_lecture_path.write_text(vimtex_root_str + header_str) diff --git a/scripts/notes.py b/scripts/notes.py index 1d83a03..93daaec 100644 --- a/scripts/notes.py +++ b/scripts/notes.py @@ -1,8 +1,9 @@ #!/usr/bin/python3 import subprocess +from pathlib import Path from lectures import Lectures, number2filename -from config import * +from config import DEFAULT_MASTER_FILE_NAME, LECTURE_START_MARKER, LECTURE_END_MARKER class Notes: