Commit 487be740 authored by Adrien Simon's avatar Adrien Simon
Browse files

Reacts triées en fonction des personnes

Vérification de la saisie lors du choix du fichier
Verification de la saisie lors du choix au menu
parent e9820de9
......@@ -4,26 +4,41 @@ import users
import json
import decode
import stats
import os
if __name__ == "__main__":
# demander le nom de la conv à analyser
name = str(input("Quel est le nom de la conversation à analyser ? "))
# get json file
data = get.getfile(name) # data = json
originpath = os.getcwd()
name = '.'
# choose action to do
choice = 0
while choice != 6:
choice = int(input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Afficher les reactions\n5 - Changer de conversation\n6 - Quitter l\'application\n"))
if name == '.':
choice = 5
else :
choice = input("\n1 - Afficher les messages\n2 - Afficher les participants\n3 - Afficher les statistiques\n4 - Afficher les reactions\n5 - Changer de conversation\n6 - Quitter l\'application\n")
try:
choice = int(choice)
except ValueError:
choice = 0
if choice == 1:
print(data)
if choice == 2:
print(users.usertab(data))
if choice == 3:
print("Affichage du nombre de messages envoyés \n")
print("\nAffichage du nombre de messages envoyés \n")
stats.printtab(stats.counttalk(users.usertab(data), data))
if choice == 4:
stats.countreacts(data)
if choice == 5:
name = str(input("Quel est le nom de la conversation à analyser ? \n"))
data = get.getfile(name)
name = '.'
while name == '.':
name = str(input( "\nQuel est le nom de la conversation à analyser ? \n"))
# get json file
try:
data = get.getfile( name ) # data = json
except IndexError:
os.chdir( originpath )
print( "Désolé, Conversation non trouvée." )
name = '.'
import decode
import users
def counttalk(usertab, data):
tmp = ""
......@@ -22,18 +23,30 @@ def printtab(tab):
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
participants = users.userdico(data)
for participant in participants:
reactions = {}
for msg in messages:
try:
for react in msg["reactions"]:
sender = decode.string_decode(react["actor"])
react = decode.string_decode(react["reaction"])
if participant == sender:
if react in reactions:
reactions[react] += 1
else:
reactions[react] = 1
participants[participant] = reactions
except KeyError:
pass
for participant in participants:
print("\n" + participant + " : ")
for react in participants[participant]:
print(react, end=' ')
print("")
for react in participants[participant]:
print(participants[participant][react], end=' ')
print("")
for react in reactions:
print(react + " : " + str(reactions[react]) + " occurences")
......@@ -17,4 +17,11 @@ def usertab(data):
usertab = userlist(data).split(',')
for i in range(len(usertab)):
usertab[i] = str(usertab[i]).strip()
return usertab
\ No newline at end of file
return usertab
def userdico(data):
userdict = {}
for participant in data["participants"]:
userdict[decode.string_decode(participant["name"])] = None
return userdict
Markdown is supported
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