1
0

Add support for specifying backup folder

This commit is contained in:
Jon Michael Aanes 2024-11-03 23:38:26 +01:00
parent 036ea124a5
commit 0050570cfb
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -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) chat_id = ' '.join(p for p in chat_id_parts if p)
return Message(sent_at, sender, text, chat_id=chat_id) 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]: 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) logger.info('Parsing %s', path)
with open(path) as f: with open(path) as f: