Groups contact book

This commit is contained in:
bursa-pastoris 2023-10-20 10:28:37 +02:00
parent 987ee029dc
commit 93728f6778
1 changed files with 15 additions and 3 deletions

View File

@ -52,13 +52,14 @@ def append_message(message):
# Extract the data
message_id = message['message_id']
sender = str(message['from']['id'])
chat_id = message['chat']['id']
chat_id = str(message['chat']['id'])
date = message['date']
text = message['text']
# Process the data
chat_file = CHAT_PATH+f'/{chat_id}.html'
sender = resolve_user(sender)
chat_id = resolve_chat(chat_id)
chat_file = CHAT_PATH+f'/{chat_id}.html'
date = dt.strftime(dt.utcfromtimestamp(date), '%Y-%m-%d %H:%M:%S') + ' UTC'
text = text.replace('\n','</p>\n<p>')
text = '<p>'+text+'</p>'
@ -89,7 +90,8 @@ def generate_pages():
# Generate chat files
chat_files = set()
for i in messages:
chat_id = i['chat']['id']
chat_id = str(i['chat']['id'])
chat_id = resolve_chat(chat_id)
chat_file = CHAT_PATH+f'/{chat_id}.html'
chat_files.add(chat_file)
for i in chat_files:
@ -121,5 +123,15 @@ def resolve_user(user_id):
return user_string
def resolve_chat(chat_id):
if chat_id in GROUP_NAMES:
chat_string = GROUP_NAMES[chat_id]
elif chat_id in USER_NAMES:
chat_string = USER_NAMES[chat_id]
else:
chat_string = f'chat_{chat_id}'
return chat_string
if __name__ == '__main__':
generate_pages()