Skip to content

Commit ea05ff9

Browse files
committed
update collection log check to also work using new list format
1 parent 1d01624 commit ea05ff9

2 files changed

Lines changed: 46 additions & 67 deletions

File tree

taskapp.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
official_status_change, username_change, get_taskCurrent_tier, generate_task_for_tier,
1414
complete_task_unofficial_tier, get_user, get_leaderboard)
1515
import send_grid_email
16-
from templesync import check_logs, read_json_file
17-
import time
16+
from templesync import check_logs
1817

1918
app = Flask(__name__)
2019

@@ -439,10 +438,10 @@ def collection_log_check():
439438
form_data = request.form
440439
rs_username = form_data['username']
441440
lms_enabled = get_lms_status(session['username'])
442-
easy_check = check_logs(rs_username, read_json_file('task-list/tiers/easy.json').get('tasks'), 'check', lms_enabled=lms_enabled)
443-
medium_check = check_logs(rs_username, read_json_file('task-list/tiers/medium.json').get('tasks'), 'check', lms_enabled=lms_enabled)
444-
hard_check = check_logs(rs_username, read_json_file('task-list/tiers/hard.json').get('tasks'), 'check', lms_enabled=lms_enabled)
445-
elite_check = check_logs(rs_username, read_json_file('task-list/tiers/elite.json').get('tasks'), 'check', lms_enabled=lms_enabled)
441+
easy_check = check_logs(rs_username, tasklists.list_for_tier('easy', lms_enabled), 'check')
442+
medium_check = check_logs(rs_username, tasklists.list_for_tier('medium', lms_enabled), 'check')
443+
hard_check = check_logs(rs_username, tasklists.list_for_tier('hard', lms_enabled), 'check')
444+
elite_check = check_logs(rs_username, tasklists.list_for_tier('elite', lms_enabled), 'check')
446445

447446
return render_template('collection_log_check.html',
448447
rs_username = rs_username,
@@ -456,10 +455,10 @@ def collection_log_check():
456455
def collection_log_import():
457456
form_data = request.form
458457
rs_username = form_data['username']
459-
easy_import = check_logs(rs_username, read_json_file('task-list/tiers/easy.json').get('tasks'), 'import')
460-
medium_import = check_logs(rs_username, read_json_file('task-list/tiers/medium.json').get('tasks'), 'import')
461-
hard_import = check_logs(rs_username, read_json_file('task-list/tiers/hard.json').get('tasks'), 'import')
462-
elite_import = check_logs(rs_username, read_json_file('task-list/tiers/elite.json').get('tasks'), 'import')
458+
easy_import = check_logs(rs_username, tasklists.list_for_tier('easy'), 'import')
459+
medium_import = check_logs(rs_username, tasklists.list_for_tier('medium'), 'import')
460+
hard_import = check_logs(rs_username, tasklists.list_for_tier('hard'), 'import')
461+
elite_import = check_logs(rs_username, tasklists.list_for_tier('elite'), 'import')
463462
all_tasks = [easy_import, medium_import, hard_import, elite_import]
464463
update = update_imported_tasks(session['username'], all_tasks, form_data['username'])
465464

templesync.py

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import requests
2-
import json
32
import tasklists
4-
import datetime
5-
import time
6-
from task_types import TaskTag
3+
from task_types import CollectionLogVerificationData, TaskData
74

85

96
def temple_player_data(username: str):
@@ -18,37 +15,31 @@ def temple_player_data(username: str):
1815

1916
return cleaned_player_data
2017

18+
# def test():
19+
# data = temple_player_data('Gerni Task')
20+
# for item in data['data']['items']:
21+
# print(item['name'])
2122

22-
def read_json_file(file_path):
23-
with open(file_path, 'r') as file:
24-
data = json.load(file)
25-
return data
23+
# def get_unix_time(timestamp: str):
24+
# datetime_format = "%Y-%m-%d %H:%M:%S"
25+
# datetime_object = datetime.datetime.strptime(timestamp, datetime_format)
26+
# return time.mktime(datetime_object.timetuple())
2627

27-
def test():
28-
data = temple_player_data('Gerni Task')
29-
for item in data['data']['items']:
30-
print(item['name'])
28+
# def import_logs(player_name: str, site_tasks: list):
29+
# player_data = temple_player_data(player_name)
30+
# completed_tasks = list()
31+
# for task in site_tasks:
32+
# task_data = task.get('colLogData', None)
33+
# if task_data:
34+
# for item in task_data['include']:
35+
# for log_slot in player_data['data']['items']:
36+
# if item['id'] == log_slot['id']:
37+
# completed_tasks.append(task['_id'])
38+
# break
39+
# return completed_tasks
3140

32-
def get_unix_time(timestamp: str):
33-
datetime_format = "%Y-%m-%d %H:%M:%S"
34-
datetime_object = datetime.datetime.strptime(timestamp, datetime_format)
35-
return time.mktime(datetime_object.timetuple())
3641

37-
def import_logs(player_name: str, site_tasks: list):
38-
player_data = temple_player_data(player_name)
39-
completed_tasks = list()
40-
for task in site_tasks:
41-
task_data = task.get('colLogData', None)
42-
if task_data:
43-
for item in task_data['include']:
44-
for log_slot in player_data['data']['items']:
45-
if item['id'] == log_slot['id']:
46-
completed_tasks.append(task['_id'])
47-
break
48-
return completed_tasks
49-
50-
51-
def check_logs(username: str, site_tasks: list, action: str, lms_enabled=True):
42+
def check_logs(username: str, site_tasks: list["TaskData"], action: str):
5243
def find_by_id(items, target_id):
5344
return [item for item in items if int(item['id']) == target_id]
5445
def format_completed_tasks(completed_tasks: set):
@@ -63,35 +54,24 @@ def format_completed_tasks(completed_tasks: set):
6354
missing_tasks = list()
6455
completed_tasks = set()
6556
for task in site_tasks:
66-
# print('******************************************************************************')
67-
task_data = task.get('colLogData', None)
68-
if TaskTag.LMS in task.get('tags', []) and action == 'check' and not lms_enabled:
57+
verification_data = task.verification
58+
if not isinstance(verification_data, CollectionLogVerificationData):
59+
print("Skipping")
6960
continue
70-
if task_data:
71-
log_count = 0
72-
for item in task_data['include']:
73-
# print(f"Checking item: {item['name']} with ID: {item['id']}")
74-
find_item = find_by_id(cleaned_player_data, item['id'])
75-
if find_item:
76-
log_count += 1
77-
# print(f"Found item: {find_item[0]['name']} with ID: {find_item[0]['id']}")
78-
# print(f"Log count: {log_count}, Required: {task_data['logCount']}")
79-
if log_count == task_data['logCount']:
80-
completed_tasks.add(task['id'])
81-
# print(f"Completed task: {task['name']} with ID: {task['uuid']}")
8261

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)
86-
break
87-
if log_count != task_data['logCount']:
88-
missing_tasks.append(task['name'])
89-
# print(f"Missing task: {task['name']} with ID: {task['uuid']}")
62+
log_count = 0
63+
for itemId in verification_data.item_ids:
64+
# print(f"Checking item: {item['name']} with ID: {item['id']}")
65+
find_item = find_by_id(cleaned_player_data, itemId)
66+
if find_item:
67+
log_count += 1
68+
69+
if log_count >= verification_data.count:
70+
completed_tasks.add(task.id)
71+
else:
72+
missing_tasks.append(task.name)
9073

9174
if action == 'check':
92-
# print("Missing tasks:")
93-
# for task in missing_tasks:
94-
# print(task)
9575
return missing_tasks
9676
else:
9777
sorted_completed_tasks = sorted(completed_tasks)
@@ -100,4 +80,4 @@ def format_completed_tasks(completed_tasks: set):
10080

10181

10282
if __name__ == "__main__":
103-
check_logs('Gerni Task', read_json_file('tasks\easy.json'), 'import')
83+
check_logs('Gerni Task', tasklists.list_for_tier('easy'), 'import')

0 commit comments

Comments
 (0)