Skip to content

Commit af2b9d8

Browse files
authored
Merge pull request #19 from mgerni/fix-temple-sync2
fix temple sync again
2 parents 437477e + dedc39d commit af2b9d8

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

templates/collection_log_import.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ <h3 class="center">Import Results For: <p class="incomplete">{{rs_username}}</p>
1818
<div class="rank-results-row center">
1919
<p class="complete">Elite Tasks: <p class="incomplete">{{elite}}</p></p>
2020
</div>
21+
<p>Reminder: Dairy Tasks are not tracked via TempleOSRS you will need to manually complete.</p>
2122
<h5 class="center">Browse a task list to see what tasks you've completed already!</h3>
2223
</div>
2324

templesync.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def import_logs(player_name: str, site_tasks: list):
4040

4141

4242
def check_logs(username: str, site_tasks: list, action: str):
43+
def find_by_id(items, target_id):
44+
return [item for item in items if item['id'] == target_id]
4345
def format_completed_tasks(completed_tasks: set):
4446
# iterate over the completed tasks and create a list of dictionaries
4547
formatted_tasks = []
@@ -49,26 +51,33 @@ def format_completed_tasks(completed_tasks: set):
4951
})
5052
return formatted_tasks
5153

52-
player_data = temple_player_data(username)
54+
cleaned_player_data = temple_player_data(username)
5355
missing_tasks = list()
5456
completed_tasks = set()
5557
for task in site_tasks:
5658
task_data = task.get('colLogData', None)
5759
if task_data:
5860
log_count = 0
5961
for item in task_data['include']:
60-
for log_slot in player_data['data']['items']:
61-
if item['id'] == log_slot['id']:
62-
log_count += 1
62+
print(f"Checking item: {item['name']} with ID: {item['id']}")
63+
find_item = find_by_id(cleaned_player_data, item['id'])
64+
if find_item:
65+
log_count += 1
66+
print(f"Found item: {find_item[0]['name']} with ID: {find_item[0]['id']}")
67+
print(f"Log count: {log_count}, Required: {task_data['logCount']}")
6368
if log_count == task_data['logCount']:
6469
completed_tasks.add(int(task['_id']))
70+
print(f"Completed task: {task['name']} with ID: {task['_id']}")
6571
break
66-
if log_count != task_data['logCount']:
67-
missing_tasks.append(task['name'])
68-
69-
72+
if log_count != task_data['logCount']:
73+
missing_tasks.append(task['name'])
74+
print(f"Missing task: {task['name']} with ID: {task['_id']}")
75+
7076
if action == 'check':
77+
print("Missing tasks:")
78+
for task in missing_tasks:
79+
print(task)
7180
return missing_tasks
7281
else:
73-
82+
print(completed_tasks)
7483
return format_completed_tasks(completed_tasks)

0 commit comments

Comments
 (0)