diff --git a/find_all_users_id.py b/find_all_users_id.py index 46b4ec7..aca351d 100644 --- a/find_all_users_id.py +++ b/find_all_users_id.py @@ -9,4 +9,14 @@ def find_all_users_id(data: dict)->list: Returns: list: List containing all the users id """ - return \ No newline at end of file + 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) \ No newline at end of file diff --git a/find_all_users_name.py b/find_all_users_name.py index 06108bf..17ceba1 100644 --- a/find_all_users_name.py +++ b/find_all_users_name.py @@ -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'))) diff --git a/find_number_of_messages.py b/find_number_of_messages.py index 5b6f303..f6b0469 100644 --- a/find_number_of_messages.py +++ b/find_number_of_messages.py @@ -10,4 +10,5 @@ def find_number_of_messages(data: dict)->int: int: Total number of messages. """ - return \ No newline at end of file + return len(data['messages']) +# print(find_number_of_messages(read_data('data/result.json'))) \ No newline at end of file diff --git a/find_user_message_count.py b/find_user_message_count.py index 6c3e6c7..dfaebc8 100644 --- a/find_user_message_count.py +++ b/find_user_message_count.py @@ -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. @@ -11,4 +11,19 @@ def find_user_message_count(data: dict, users_id: str)->dict: Returns: dict: Number of messages of the users """ - return \ No newline at end of file + 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))) \ No newline at end of file diff --git a/read_data.py b/read_data.py index 269ada5..6cfe853 100644 --- a/read_data.py +++ b/read_data.py @@ -9,5 +9,9 @@ def read_data(file_path: str)->dict: dict: Dictionary containing the data of the json file. """ - #open file - return \ No newline at end of file + f=open(file_path, encoding="utf8") + s=json.loads(f.read()) + + return s + +# print(read_data('./data/result.json')) \ No newline at end of file