1
0
This commit is contained in:
Jon Michael Aanes 2024-11-03 17:15:03 +01:00
parent 8cec980d31
commit b0c81bc95b
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 8 additions and 4 deletions

View File

@ -109,8 +109,7 @@ def main():
for chat_id, messages_in_chat_original in messages_by_chat_id.items(): for chat_id, messages_in_chat_original in messages_by_chat_id.items():
messages_in_chat = merge_adjacent_messages(messages_in_chat_original) messages_in_chat = merge_adjacent_messages(messages_in_chat_original)
if len(messages_in_chat) <= 2: if len(messages_in_chat) <= 2:
logger.info( logger.info(' "%s": Skipped due to too few messages', chat_id)
' "%s": Skipped due to too few messages', chat_id)
continue continue
messages_by_period = group_messages_by_period(messages_in_chat) messages_by_period = group_messages_by_period(messages_in_chat)
@ -123,8 +122,10 @@ def main():
) )
for period_key, messages in messages_by_period.items(): for period_key, messages in messages_by_period.items():
file_escaped_chat_id = chat_id.replace(' ','-') file_escaped_chat_id = chat_id.replace(' ', '-')
output_file = args.output / chat_id / f'{file_escaped_chat_id}-{period_key}.md' output_file = (
args.output / chat_id / f'{file_escaped_chat_id}-{period_key}.md'
)
output_file.parent.mkdir(exist_ok=True) output_file.parent.mkdir(exist_ok=True)
logger.info('Writing % 5d messages to %s', len(messages), output_file) logger.info('Writing % 5d messages to %s', len(messages), output_file)
with open(output_file, 'w') as f: with open(output_file, 'w') as f:

View File

@ -17,6 +17,7 @@ from .data import MYSELF, Message
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def is_named_number(num: str) -> str: def is_named_number(num: str) -> str:
try: try:
int(num.removeprefix('+').replace(' ', '')) int(num.removeprefix('+').replace(' ', ''))
@ -24,6 +25,7 @@ def is_named_number(num: str) -> str:
except ValueError: except ValueError:
return True return True
def normalize_phone_number(num: str) -> str: def normalize_phone_number(num: str) -> str:
if is_named_number(num): if is_named_number(num):
return num return num

View File

@ -10,5 +10,6 @@ def test_normalize_phone_number():
assert synctech_sms.normalize_phone_number('441234567890') == '+441234567890' assert synctech_sms.normalize_phone_number('441234567890') == '+441234567890'
assert synctech_sms.normalize_phone_number('004712345678') == '+4712345678' assert synctech_sms.normalize_phone_number('004712345678') == '+4712345678'
def test_dont_normalize_weird(): def test_dont_normalize_weird():
assert synctech_sms.normalize_phone_number('Midttrafik') == 'Midttrafik' assert synctech_sms.normalize_phone_number('Midttrafik') == 'Midttrafik'