11import requests
22import json
3+ import tasklists
4+ import datetime
5+ import time
36
47
58def temple_player_data (username : str ):
@@ -25,6 +28,11 @@ def test():
2528 for item in data ['data' ]['items' ]:
2629 print (item ['name' ])
2730
31+ def get_unix_time (timestamp : str ):
32+ datetime_format = "%Y-%m-%d %H:%M:%S"
33+ datetime_object = datetime .datetime .strptime (timestamp , datetime_format )
34+ return time .mktime (datetime_object .timetuple ())
35+
2836def import_logs (player_name : str , site_tasks : list ):
2937 player_data = temple_player_data (player_name )
3038 completed_tasks = list ()
@@ -39,26 +47,26 @@ def import_logs(player_name: str, site_tasks: list):
3947 return completed_tasks
4048
4149
42- def check_logs (username : str , site_tasks : list , action : str ):
50+ def check_logs (username : str , site_tasks : list , action : str , lms_enabled = True ):
4351 def find_by_id (items , target_id ):
44- print (type (target_id ))
45-
4652 return [item for item in items if int (item ['id' ]) == target_id ]
4753 def format_completed_tasks (completed_tasks : set ):
48- # iterate over the completed tasks and create a list of dictionaries
4954 formatted_tasks = []
5055 for task_id in completed_tasks :
5156 formatted_tasks .append ({
5257 'taskId' : task_id ,
5358 })
59+ print (formatted_tasks )
5460 return formatted_tasks
5561
5662 cleaned_player_data = temple_player_data (username )
57- print (type (cleaned_player_data ))
5863 missing_tasks = list ()
5964 completed_tasks = set ()
6065 for task in site_tasks :
66+ print ('******************************************************************************' )
6167 task_data = task .get ('colLogData' , None )
68+ if task .get ('isLMS' ) and action == 'check' and not lms_enabled :
69+ continue
6270 if task_data :
6371 log_count = 0
6472 for item in task_data ['include' ]:
@@ -71,6 +79,10 @@ def format_completed_tasks(completed_tasks: set):
7179 if log_count == task_data ['logCount' ]:
7280 completed_tasks .add (int (task ['_id' ]))
7381 print (f"Completed task: { task ['name' ]} with ID: { task ['_id' ]} " )
82+
83+ if action == "import" and find_item [0 ].get ('date' , None ):
84+ unix_time = get_unix_time (find_item [0 ]['date' ])
85+ print (find_item [0 ]['date' ], unix_time )
7486 break
7587 if log_count != task_data ['logCount' ]:
7688 missing_tasks .append (task ['name' ])
@@ -84,4 +96,8 @@ def format_completed_tasks(completed_tasks: set):
8496 else :
8597 sorted_completed_tasks = sorted (completed_tasks )
8698 print (sorted_completed_tasks )
87- return format_completed_tasks (sorted_completed_tasks )
99+ return format_completed_tasks (sorted_completed_tasks )
100+
101+
102+ if __name__ == "__main__" :
103+ check_logs ('Gerni Task' , read_json_file ('tasks\easy.json' ), 'import' )
0 commit comments