forked from OSRS-Taskman/Taskapp_Public
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplesync.py
More file actions
81 lines (67 loc) · 2.84 KB
/
templesync.py
File metadata and controls
81 lines (67 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import requests
import tasklists
from task_types import CollectionLogVerificationData, TaskData
def temple_player_data(username: str):
username = username.replace(' ', '+')
player_data = requests.get(f'https://templeosrs.com/api/collection-log/player_collection_log.php?player={username}&categories=all&itemsonly&includenames=1&onlyitems=1').json()
used_id = set()
cleaned_player_data = list()
for item in player_data['data']['items']:
if item['id'] not in used_id:
used_id.add(item['id'])
cleaned_player_data.append(item)
return cleaned_player_data
# def test():
# data = temple_player_data('Gerni Task')
# for item in data['data']['items']:
# print(item['name'])
# def get_unix_time(timestamp: str):
# datetime_format = "%Y-%m-%d %H:%M:%S"
# datetime_object = datetime.datetime.strptime(timestamp, datetime_format)
# return time.mktime(datetime_object.timetuple())
# def import_logs(player_name: str, site_tasks: list):
# player_data = temple_player_data(player_name)
# completed_tasks = list()
# for task in site_tasks:
# task_data = task.get('colLogData', None)
# if task_data:
# for item in task_data['include']:
# for log_slot in player_data['data']['items']:
# if item['id'] == log_slot['id']:
# completed_tasks.append(task['_id'])
# break
# return completed_tasks
def check_logs(username: str, site_tasks: list["TaskData"], action: str):
def find_by_id(items, target_id):
return [item for item in items if int(item['id']) == target_id]
def format_completed_tasks(completed_tasks: set):
formatted_tasks = []
for task_id in completed_tasks:
formatted_tasks.append({
'id' : task_id
})
return formatted_tasks
cleaned_player_data = temple_player_data(username)
missing_tasks = list()
completed_tasks = set()
for task in site_tasks:
verification_data = task.verification
if not isinstance(verification_data, CollectionLogVerificationData):
continue
log_count = 0
for item_id in verification_data.item_ids:
# print(f"Checking item: {item['name']} with ID: {item['id']}")
if find_by_id(cleaned_player_data, item_id):
log_count += 1
if log_count >= verification_data.count:
completed_tasks.add(task.id)
else:
missing_tasks.append(task.name)
if action == 'check':
return missing_tasks
else:
sorted_completed_tasks = sorted(completed_tasks)
# print(sorted_completed_tasks)
return format_completed_tasks(sorted_completed_tasks)
if __name__ == "__main__":
check_logs('Gerni Task', tasklists.list_for_tier('easy'), 'import')