mnemocron / TelegramChatStats

Generate some statistics and plots from your exported Telegram chat data (using Bokeh plots with python 3)
MIT License
56 stars 12 forks source link

Filter out unsupported messages #6

Closed Cycatz closed 2 years ago

Cycatz commented 2 years ago

Some messages are unsupported by some versions of Telegram, which caused the following error when running the script. image

Traceback (most recent call last):
  File "/tmp/TelegramChatStats/./telegram-statistics.py", line 196, in <module>
    main()
  File "/tmp/TelegramChatStats/./telegram-statistics.py", line 177, in main
    raw = calculate_graphs(chat_data, date_filter, wordlist)
  File "/tmp/TelegramChatStats/./telegram-statistics.py", line 118, in calculate_graphs
    return _message_graphs(chat_data, date_filter, wordlist)
  File "/tmp/TelegramChatStats/_message_graphs.py", line 171, in _message_graphs
    metrics = _parse_chat(chat, date_filter, wordlist)
  File "/tmp/TelegramChatStats/_message_graphs.py", line 69, in _parse_chat
    date_obj = datetime.strptime(message['date'], '%Y-%m-%dT%H:%M:%S')
KeyError: 'date'

The structure of a unsupported message is similar to this:

{'id': 43178, 'type': 'unsupported'}

Therefore I add an if statement at the top of the for loop to check if the type of this message is 'unsupported'; if yes, skip this message.