From 0050570cfb48ebe84fbeec544b016da22629d323 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Sun, 3 Nov 2024 23:38:26 +0100 Subject: [PATCH] Add support for specifying backup folder --- libpurple_to_markdown/synctech_sms.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libpurple_to_markdown/synctech_sms.py b/libpurple_to_markdown/synctech_sms.py index aae2f22..d612779 100644 --- a/libpurple_to_markdown/synctech_sms.py +++ b/libpurple_to_markdown/synctech_sms.py @@ -65,8 +65,15 @@ def sms_soup_to_message(soup: bs4.BeautifulSoup) -> Message: chat_id = ' '.join(p for p in chat_id_parts if p) return Message(sent_at, sender, text, chat_id=chat_id) +def select_newest_file_in_dir(path: Path) -> Path: + return min((p for p in path.iterdir() if p.suffix == '.xml' and 'sms' in p.name), key = lambda p: p.stat().st_atime_ns) def parse_messages_in_backup_xml_file(path: Path) -> Iterator[Message]: + if path.is_dir(): + logger.info('%s is a dir. Finding newest backup in directory', path) + path = select_newest_file_in_dir(path) + logger.info('Found: %s', path) + logger.info('Parsing %s', path) with open(path) as f: