Commit 545b3bc0 authored by Adrien Simon's avatar Adrien Simon
Browse files

stats des reacts

parent fcceaf1a
......@@ -11,3 +11,4 @@ def timestamp_decode(date_ts):
time_dt = str(date_dt)[-8:] # on prend les 8 derniers caracteres pour recup l'heure
date_dt = date_dt.strftime('%d-%m-%Y') + " " + time_dt # on concatene la date en dd-mm-yyyy et l'heure
return date_dt
......@@ -13,8 +13,8 @@ if __name__ == "__main__":
data = get.getfile(name) # data = json
# choose action to do
choice = 0
while choice != 4:
choice = int(input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Quitter l\'application\n"))
while choice != 5:
choice = int(input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Afficher les reactions\n5 - Quitter l\'application\n"))
if choice == 1:
print(data)
if choice == 2:
......@@ -22,3 +22,5 @@ if __name__ == "__main__":
if choice == 3:
print("Affichage du nombre de messages envoyés \n")
stats.printtab(stats.counttalk(users.usertab(data), data))
if choice == 4:
stats.countreacts(data)
......@@ -19,3 +19,20 @@ def counttalk(usertab, data):
def printtab(tab):
for i in range(len(tab[0])):
print(str(tab[0][i]) + " : " + str(tab[1][i]) + " messages")
def countreacts(data):
reactions = {}
messages = data["messages"]
for msg in messages:
try:
for react in msg["reactions"]:
react = decode.string_decode(react["reaction"])
if react in reactions:
reactions[react] += 1
else:
reactions[react] = 1
except KeyError:
pass
print(reactions)
\ No newline at end of file
......@@ -2,4 +2,4 @@ import json
import os
def tri():
print("Hello tri\n")
\ No newline at end of file
pass
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment