diff --git a/libpurple_to_markdown/__init__.py b/libpurple_to_markdown/__init__.py index 56b3b1e..f150ae8 100644 --- a/libpurple_to_markdown/__init__.py +++ b/libpurple_to_markdown/__init__.py @@ -88,11 +88,12 @@ def is_adjacent_messages(first: Message, second: Message) -> bool: and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST ) -PUNCTUATION = ('.','?','!',',',':',';') + +PUNCTUATION = ('.', '?', '!', ',', ':', ';') + def merge_texts(text1: str, text2: str) -> str: punctuated = text1.endswith(PUNCTUATION) - # return text1 + (' ' if punctuated else '. ') + text2 return text1 + ('' if punctuated else '.') + '\n' + text2 diff --git a/libpurple_to_markdown/markdown.py b/libpurple_to_markdown/markdown.py index de31a8f..65536b5 100644 --- a/libpurple_to_markdown/markdown.py +++ b/libpurple_to_markdown/markdown.py @@ -1,4 +1,3 @@ - import re from .data import Message @@ -11,6 +10,7 @@ def normalize_line(line: str) -> str: line = re.sub(r'\s+([.:;!?])', r'\1', line) return line.strip() + def format_message_as_citation(out: list[str], msg: Message) -> None: out.append(f'{msg.sent_at.date()} {msg.sent_at.time()} [[{msg.sender}]]:') out.append('\n') diff --git a/libpurple_to_markdown/synctech_sms.py b/libpurple_to_markdown/synctech_sms.py index d612779..55f1748 100644 --- a/libpurple_to_markdown/synctech_sms.py +++ b/libpurple_to_markdown/synctech_sms.py @@ -65,8 +65,13 @@ 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) + 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(): diff --git a/test/test_join.py b/test/test_join.py index 3dc2820..1bb78ea 100644 --- a/test/test_join.py +++ b/test/test_join.py @@ -1,9 +1,7 @@ -import datetime - from libpurple_to_markdown import merge_texts + def test_merge(): assert merge_texts('Hello World', 'Hello World.') == 'Hello World.\nHello World.' assert merge_texts('Hello World.', 'Hello World.') == 'Hello World.\nHello World.' assert merge_texts('Hello World?', 'Hello World.') == 'Hello World?\nHello World.' - diff --git a/test/test_markdown_format.py b/test/test_markdown_format.py index 0251262..9cebc79 100644 --- a/test/test_markdown_format.py +++ b/test/test_markdown_format.py @@ -1,14 +1,14 @@ import datetime -from libpurple_to_markdown.markdown import format_messages from libpurple_to_markdown.data import Message +from libpurple_to_markdown.markdown import format_messages NOW = datetime.datetime.fromtimestamp(1_000_000_000, tz=datetime.UTC) TEXT_1 = 'Hello \nWorld \n ' -EXPECTED_1='''# Test +EXPECTED_1 = """# Test --- ## [[2001-09-09]] @@ -21,7 +21,8 @@ EXPECTED_1='''# Test > Hello > World -''' +""" + def test_whitespace_at_end_of_line(): msg = Message(NOW, 'Test Sender', TEXT_1, 'Test Chat')