Skip to content

Commit d0dbbfd

Browse files
committed
lms_rank_check
1 parent 166b978 commit d0dbbfd

3 files changed

Lines changed: 69 additions & 18 deletions

File tree

task_database.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ def uncomplete_all_tasks(username):
836836
coll.update_one({'username': username, '%s._id' % tier: task_id},
837837
{'$set': {'%s.$.taskCurrent' % tier: False, '%s.$.status' % tier: 'Incomplete'}})
838838

839+
def get_lms_status(username):
840+
coll = mydb["taskLists"]
841+
lms_enabled = coll.find_one({"username": username}, {'lmsEnabled' : 1, '_id': 0})
842+
return lms_enabled["lmsEnabled"]
839843

840844
'''
841845
lms_status_change:
@@ -1382,9 +1386,42 @@ def test():
13821386

13831387
def fix_gerni():
13841388
task_coll = mydb["taskLists"]
1385-
task_coll.update_one({"username": "GerniFix"})
1386-
results = task_coll.find({}, {'tiers': 1, 'username': 1})
1389+
# task_coll.update_one({"username": "EscFromTaskov"})
1390+
results = task_coll.find({}, {'tiers': 1, '_id' : 0, 'username': 1})
1391+
tiers = ['easy', 'medium', 'hard', 'elite', 'master', 'passive', 'extra', 'bossPets', 'skillPets', 'otherPets']
1392+
for result in results:
1393+
for tier in tiers:
1394+
tasks = result["tiers"][tier]['completedTasks']
1395+
data = set()
1396+
to_remove = set()
1397+
for i, completed_task in enumerate(tasks):
1398+
task_id = completed_task["taskId"]
1399+
if task_id not in data:
1400+
data.add(task_id)
1401+
else:
1402+
to_remove.add(task_id)
1403+
print(result['username'], tier, i, task_id)
1404+
if to_remove:
1405+
print(to_remove)
1406+
# for _id in to_remove:
1407+
# task_coll.update_one(
1408+
# {
1409+
# "username" : result['username']
1410+
# },
1411+
# {
1412+
# "$pull" : {
1413+
# f"tiers.{tier}.completedTasks" : {"taskId" : _id}
1414+
# }
1415+
# })
1416+
# task_coll.update_one(
1417+
# {"username": result['username']},
1418+
# {
1419+
# "$push": {
1420+
# f"tiers.{tier}.completedTasks": {"taskId": _id}
1421+
# }
1422+
# }
1423+
# )
13871424
if __name__ == "__main__":
1388-
# test()
1389-
get_task_lists('GerniSleep')
1425+
fix_gerni()
1426+
# get_task_lists('GerniSleep')
13901427
pass

taskapp.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import tasklists
1010
from task_database import (get_taskCurrent, generate_task, complete_task, get_task_progress,
1111
get_task_lists, manual_complete_tasks, manual_revert_tasks,
12-
uncomplete_all_tasks, lms_status_change, update_imported_tasks,
12+
get_lms_status, lms_status_change, update_imported_tasks,
1313
official_status_change, username_change, official_icon, unofficial_icon, get_taskCurrent_tier, generate_task_for_tier,
1414
complete_task_unofficial_tier, get_user, get_leaderboard)
1515
import send_grid_email
@@ -446,10 +446,11 @@ def dashboard():
446446
def collection_log_check():
447447
form_data = request.form
448448
rs_username = form_data['username']
449-
easy_check = check_logs(rs_username, read_json_file('tasks/easy.json'), 'check')
450-
medium_check = check_logs(rs_username, read_json_file('tasks/medium.json'), 'check')
451-
hard_check = check_logs(rs_username, read_json_file('tasks/hard.json'), 'check')
452-
elite_check = check_logs(rs_username, read_json_file('tasks/elite.json'),'check')
449+
lms_enabled = get_lms_status(session['username'])
450+
easy_check = check_logs(rs_username, read_json_file('tasks/easy.json'), 'check', lms_enabled=lms_enabled)
451+
medium_check = check_logs(rs_username, read_json_file('tasks/medium.json'), 'check', lms_enabled=lms_enabled)
452+
hard_check = check_logs(rs_username, read_json_file('tasks/hard.json'), 'check', lms_enabled=lms_enabled)
453+
elite_check = check_logs(rs_username, read_json_file('tasks/elite.json'),'check', lms_enabled=lms_enabled)
453454

454455
return render_template('collection_log_check.html',
455456
rs_username = rs_username,
@@ -476,9 +477,6 @@ def collection_log_import():
476477
medium = len(medium_import),
477478
hard = len(hard_import),
478479
elite = len(elite_import))
479-
480-
481-
return {'message': easy_import}
482480

483481
# AJAX route for generating a task.
484482
@app.route('/generate/', methods=['POST'])

templesync.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import requests
22
import json
3+
import tasklists
4+
import datetime
5+
import time
36

47

58
def 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+
2836
def 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

Comments
 (0)