k-mktr commited on
Commit
893d387
1 Parent(s): 4af6b14

Update leaderboard.py

Browse files
Files changed (1) hide show
  1. leaderboard.py +28 -2
leaderboard.py CHANGED
@@ -2,7 +2,9 @@ from nc_py_api import Nextcloud
2
  import json
3
  from typing import Dict, Any
4
  import os
5
-
 
 
6
  import arena_config
7
 
8
  # Initialize Nextcloud client
@@ -44,4 +46,28 @@ def update_leaderboard(winner: str, loser: str) -> Dict[str, Any]:
44
 
45
  # Function to get the current leaderboard
46
  def get_current_leaderboard() -> Dict[str, Any]:
47
- return load_leaderboard()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import json
3
  from typing import Dict, Any
4
  import os
5
+ import time
6
+ from datetime import datetime
7
+ import threading
8
  import arena_config
9
 
10
  # Initialize Nextcloud client
 
46
 
47
  # Function to get the current leaderboard
48
  def get_current_leaderboard() -> Dict[str, Any]:
49
+ return load_leaderboard()
50
+
51
+ def create_backup():
52
+ while True:
53
+ try:
54
+ leaderboard_data = load_leaderboard()
55
+
56
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
57
+ backup_file_name = f"leaderboard_backup_{timestamp}.json"
58
+ backup_path = f"{arena_config.NEXTCLOUD_BACKUP_FOLDER}/{backup_file_name}"
59
+
60
+ json_data = json.dumps(leaderboard_data, indent=2)
61
+
62
+ nc.files.upload(backup_path, json_data.encode('utf-8'))
63
+
64
+ print(f"Backup created on Nextcloud: {backup_path}")
65
+
66
+ except Exception as e:
67
+ print(f"Error creating backup: {e}")
68
+
69
+ time.sleep(3600) # Sleep for 1 hour
70
+
71
+ def start_backup_thread():
72
+ backup_thread = threading.Thread(target=create_backup, daemon=True)
73
+ backup_thread.start()