Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion find_all_users_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ def find_all_users_id(data: dict)->list:
Returns:
list: List containing all the users id
"""
return
s=set()
for i in data['messages']:
if i.get('actor_id')!=None:
s.add(i['actor_id'])
else:
s.add(i['from_id'])
return s
# data=find_all_users_id(read_data('data/result.json'))
# print(read_data('data/result.json'))

# print(data)
9 changes: 8 additions & 1 deletion find_all_users_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ def find_all_users_name(data: dict)->list:
Returns:
list: List containing all the users name.
"""
return
s=set()
for i in data["messages"]:
if i.get('actor')!=None:
s.add(i['actor'])
else:
s.add(i['from'])
return s
# print(find_all_users_name(read_data('data/result.json')))
3 changes: 2 additions & 1 deletion find_number_of_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ def find_number_of_messages(data: dict)->int:
int: Total number of messages.

"""
return
return len(data['messages'])
# print(find_number_of_messages(read_data('data/result.json')))
19 changes: 17 additions & 2 deletions find_user_message_count.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from read_data import read_data
from find_all_users_id import find_all_users_id

def find_user_message_count(data: dict, users_id: str)->dict:
def find_user_message_count(data: dict, users_id: list)->dict:
"""
This function will find the user's message count.

Expand All @@ -11,4 +11,19 @@ def find_user_message_count(data: dict, users_id: str)->dict:
Returns:
dict: Number of messages of the users
"""
return
s={}
for j in users_id:
x = 0
for i in data['messages']:
if i.get('actor_id')!=None:
if i['actor_id']==j:
x+=1
else:
if i['from_id']==j:
x+=1
s[j] = x
return s
# data=read_data('data/result.json')
# users_id = find_all_users_id(data)

# print(find_user_message_count(data, list(users_id)))
8 changes: 6 additions & 2 deletions read_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ def read_data(file_path: str)->dict:
dict: Dictionary containing the data of the json file.

"""
#open file
return
f=open(file_path, encoding="utf8")
s=json.loads(f.read())

return s

# print(read_data('./data/result.json'))