Ruff
This commit is contained in:
parent
7568b862e2
commit
c325e747fa
|
@ -88,11 +88,12 @@ def is_adjacent_messages(first: Message, second: Message) -> bool:
|
||||||
and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST
|
and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
PUNCTUATION = ('.', '?', '!', ',', ':', ';')
|
PUNCTUATION = ('.', '?', '!', ',', ':', ';')
|
||||||
|
|
||||||
|
|
||||||
def merge_texts(text1: str, text2: str) -> str:
|
def merge_texts(text1: str, text2: str) -> str:
|
||||||
punctuated = text1.endswith(PUNCTUATION)
|
punctuated = text1.endswith(PUNCTUATION)
|
||||||
# return text1 + (' ' if punctuated else '. ') + text2
|
|
||||||
return text1 + ('' if punctuated else '.') + '\n' + text2
|
return text1 + ('' if punctuated else '.') + '\n' + text2
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .data import Message
|
from .data import Message
|
||||||
|
@ -11,6 +10,7 @@ def normalize_line(line: str) -> str:
|
||||||
line = re.sub(r'\s+([.:;!?])', r'\1', line)
|
line = re.sub(r'\s+([.:;!?])', r'\1', line)
|
||||||
return line.strip()
|
return line.strip()
|
||||||
|
|
||||||
|
|
||||||
def format_message_as_citation(out: list[str], msg: Message) -> None:
|
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(f'{msg.sent_at.date()} {msg.sent_at.time()} [[{msg.sender}]]:')
|
||||||
out.append('\n')
|
out.append('\n')
|
||||||
|
|
|
@ -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)
|
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:
|
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]:
|
def parse_messages_in_backup_xml_file(path: Path) -> Iterator[Message]:
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import datetime
|
|
||||||
|
|
||||||
from libpurple_to_markdown import merge_texts
|
from libpurple_to_markdown import merge_texts
|
||||||
|
|
||||||
|
|
||||||
def test_merge():
|
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.'
|
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.'
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from libpurple_to_markdown.markdown import format_messages
|
|
||||||
from libpurple_to_markdown.data import Message
|
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)
|
NOW = datetime.datetime.fromtimestamp(1_000_000_000, tz=datetime.UTC)
|
||||||
|
|
||||||
|
|
||||||
TEXT_1 = 'Hello \nWorld \n '
|
TEXT_1 = 'Hello \nWorld \n '
|
||||||
|
|
||||||
EXPECTED_1='''# Test
|
EXPECTED_1 = """# Test
|
||||||
|
|
||||||
---
|
---
|
||||||
## [[2001-09-09]]
|
## [[2001-09-09]]
|
||||||
|
@ -21,7 +21,8 @@ EXPECTED_1='''# Test
|
||||||
> Hello
|
> Hello
|
||||||
> World
|
> World
|
||||||
|
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_whitespace_at_end_of_line():
|
def test_whitespace_at_end_of_line():
|
||||||
msg = Message(NOW, 'Test Sender', TEXT_1, 'Test Chat')
|
msg = Message(NOW, 'Test Sender', TEXT_1, 'Test Chat')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user