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: