From 7495495cc1c9058f084ce8e2086b813ded9fe4c8 Mon Sep 17 00:00:00 2001 From: valoka Date: Mon, 2 Dec 2024 23:28:34 +0900 Subject: [PATCH] bruh moments number 1 --- .gitignore | 3 ++ main.py | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 4 ++ 3 files changed, 142 insertions(+) create mode 100644 .gitignore create mode 100644 main.py create mode 100644 test.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6afb824 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/chats +/figs +/.venv \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..60dc41a --- /dev/null +++ b/main.py @@ -0,0 +1,135 @@ +import json +from datetime import datetime, timedelta +from dateutil import parser +from matplotlib import pyplot as plt +import pandas as pd +import glob, os + + +#consts +valo = 'user452708124' +starttime = datetime(2018, 9, 16) +endtime = datetime(2024, 11, 4) +colors = ['red', 'orange', 'yellow', 'blue', 'black', 'green', 'purple', 'pink', 'cyan', 'grey', 'magenta', 'brown'] + +with open('/home/valoka/Downloads/Telegram Desktop/nsfw/result.json', 'r') as file: + json_file = json.load(file) + +def get_by_date(json_file, date): + table = [] + + for i in json_file["messages"]: + if i["date"].find(date) != -1: + table.append(i["text"]) + + return table + +def process(input_file): + count0 = 0; count11 = 0 + count1 = 0; count01 = 0 + + main_dict = {} + + #get partner name + #"name": "Анастэйша" + partner_name = input_file["name"] + partner_id = "user" + str(input_file["id"]) + + for i in input_file["messages"]: + #count messages + if i['type'] == 'message': + if i['from_id'] == valo: + count0 += 1 + else: + count1 += 1 + + main_dict.update(mes0 = count0, mes1 = count1) + + #count emoji + try: + for o in i["reactions"]: + if o['type'] == "emoji" and o["emoji"] == "❤": + for p in o['recent']: + #print(p['from_id']) + if p['from_id'] == valo: + count01 += 1 + if p['from_id'] == partner_id: + count11 += 1 + except: + pass + + main_dict.update(emj0 = count01, emj1 = count11) + + return partner_name, main_dict + +def dateF(oldDate, days): + dateBefore = parser.parse(str(oldDate)) + return dateBefore + timedelta(days) + +def get_partner_name(filepath: str) -> str: + with open(filepath, 'r') as name: + json_file = json.load(name) + try: + return "Liza" if str(json_file["name"]) == "🍭" else str(json_file["name"]) + except: + return str("Saved messages") + +# print(process(json_file)) +name_list = [glob.glob(f'{os.getcwd()}/chats/*')] +nicknames = [] +sums = [0 for _ in name_list[0]] + +print(process(json_file)) + +for i in range(0,73): + print(dateF(datetime(2024,9,11), i).strftime("%Y-%m-%d"), len(get_by_date(json_file, dateF(datetime(2024,9,11), i).strftime("%Y-%m-%d")))) + + +exit(0) + +for i in name_list[0]: + nicknames.append(get_partner_name(i)) +print(nicknames) + +for i in range((endtime - starttime).days): + for o in range(len(name_list[0])): + with open(name_list[0][o], 'r') as file: + json_file = json.load(file) + + sums[o] += len(get_by_date(json_file, dateF(starttime, i).strftime("%Y-%m-%d"))) + + data = {'Чаты' : nicknames, + 'Количество' : sums, + 'Colors': colors} + + dataFrame = pd.DataFrame(data=data) + dataFrame.sort_values(by='Количество', inplace=True) + + #df = pd.DataFrame({'Чаты' : nicknames, 'Количество' : sums}) + #df_sorted = df.sort_values('Количество') + dataFrame.plot.barh(x = 'Чаты', y = 'Количество', color = dataFrame['Colors'], + title="Chat Statistics", ylabel="Nickname", + xlabel = "Amount of messages (number)", figsize=(16,9), + label=f"Total: {sum(sums)}\nDate: {dateF(starttime, i).strftime("%Y-%m-%d")}") + #dataFrame.plot(title="Chat Statistics", ylabel="Chat name (nickname)", + # xlabel = "Amount of messages (number)", figsize=(16,9)) + #dataFrame.plot.figure(figsize=(16,9), dpi=100) + # plt.title("Chat Statistics") + # plt.xlabel("Amount of messages (number)") + # plt.ylabel("Chat name (nickname)") + # plt.plot([], [], ' ', label=f"Total: {sum(sums)}") + # plt.legend(loc="upper right") + #plt.yticks(ticks=[i for i in range(12)], labels=nicknames) + + + #plt.show() + #plt.barh(df_sorted['Чаты'], df_sorted['Количество'], data=df_sorted, color=colors) + + plt.savefig(f'/home/valoka/SomeCode/pethon/figs/{i:05}-{dateF(starttime, i).strftime("%Y-%m-%d")}.png') + plt.close() + + print(dateF(starttime, i)) + print(sums) + + file.close() + diff --git a/test.py b/test.py new file mode 100644 index 0000000..81df1cc --- /dev/null +++ b/test.py @@ -0,0 +1,4 @@ +from datetime import datetime, timedelta + +starttime = datetime(2024, 9, 16) +print(starttime + timedelta(72)) \ No newline at end of file