feat: Add song difficulty leaderboard feature
This commit is contained in:
43
tools/reset_leaderboard.py
Normal file
43
tools/reset_leaderboard.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pymongo import MongoClient
|
||||
|
||||
# Add project root to path
|
||||
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
|
||||
try:
|
||||
import config
|
||||
except ImportError:
|
||||
# Handle case where config might not be in path or environment variables are used
|
||||
config = None
|
||||
|
||||
def reset_leaderboard():
|
||||
"""Delete leaderboard entries not from the current month"""
|
||||
mongo_host = os.environ.get("TAIKO_WEB_MONGO_HOST")
|
||||
if not mongo_host and config:
|
||||
mongo_host = config.MONGO['host']
|
||||
|
||||
db_name = "taiko"
|
||||
if config:
|
||||
db_name = config.MONGO['database']
|
||||
|
||||
if not mongo_host:
|
||||
print("Error: content not found for MONGO_HOST")
|
||||
return
|
||||
|
||||
client = MongoClient(host=mongo_host)
|
||||
db = client[db_name]
|
||||
|
||||
current_month = datetime.now().strftime('%Y-%m')
|
||||
|
||||
# Delete old month data
|
||||
result = db.leaderboard.delete_many({'month': {'$ne': current_month}})
|
||||
|
||||
print(f"Deleted {result.deleted_count} old leaderboard entries")
|
||||
print(f"Current month: {current_month}")
|
||||
|
||||
client.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
reset_leaderboard()
|
||||
Reference in New Issue
Block a user