From dd8f68ab902a774067322b34d87a1ca86a57a2fe Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Wed, 10 Nov 2021 15:02:55 -0500 Subject: [PATCH] [+] Jannchie animation --- telegram-history-analysis/time-animation.py | 59 +++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 telegram-history-analysis/time-animation.py diff --git a/telegram-history-analysis/time-animation.py b/telegram-history-analysis/time-animation.py new file mode 100644 index 0000000..6eb2fdf --- /dev/null +++ b/telegram-history-analysis/time-animation.py @@ -0,0 +1,59 @@ +import io +import json +import json5 + +if __name__ == '__main__': + """ + + """ + file = "./result.json" + start = '2021-06-25T12:01:01' + end = '2021-11-02T14:01:01' + + with io.open(file, mode='r', encoding="utf-8") as f: + content = f.read() + obj = json5.loads(content) + + with io.open('userid_to_name.json5', mode='r', encoding='utf-8') as f: + userid_to_name = json.loads(f.read()) + + messages: list = obj['messages'] + messages = [m for m in messages if True + # and start < m['date'] < end + and m['type'] == 'message' + # and m['from'] == 'Hykilpikonna' + ] + + date_data = {} + for m in messages: + date = m['date'][:10] + if date not in date_data: + date_data[date] = {} + user = m['from_id'] + if user not in userid_to_name: + userid_to_name[user] = m['from'] + user = userid_to_name[user] + if user not in date_data[date]: + date_data[date][user] = 0 + date_data[date][user] += 1 + + print(userid_to_name) + + user_totals = {} + lines = ['id,date,value'] + for date in date_data: + users = date_data[date] + for u in users: + if u not in user_totals: + user_totals[u] = 0 + user_totals[u] += users[u] + + for u in user_totals: + total = user_totals[u] + if u in userid_to_name: + u = userid_to_name[u] + lines.append(f'{u},{date},{total}') + + with io.open('output.csv', mode='w', encoding='utf-8') as f: + f.write('\n'.join(lines)) +