-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTool-03-Case-Number-Normalizer-UNIFIED-2.py
60 lines (46 loc) · 2.04 KB
/
Tool-03-Case-Number-Normalizer-UNIFIED-2.py
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
import json
import time
def get_current_timestamp():
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def fix_account_numbers(file_path):
print(
f"[{get_current_timestamp()}] Starting to fix account numbers in the file: {file_path}"
)
try:
with open(file_path, "r", encoding="utf-8") as f:
data = json.load(f)
print(
f"[{get_current_timestamp()}] Successfully loaded the data from the file."
)
except Exception as e:
print(f"[{get_current_timestamp()}] Error loading the file: {e}")
return
total_accounts = len(data)
updated_count = 0
updated_data = {}
# Iterate through the accounts and update both the keys and the CASE_NUMBER
for index, (old_key, account) in enumerate(data.items(), start=1):
# Generate the new key (e.g., ACCOUNT_NUMBER_1, ACCOUNT_NUMBER_2, etc.)
new_key = f"ACCOUNT_NUMBER_{index}"
# Remove the 'ACCOUNT_NUMBER_' field if it exists
if "ACCOUNT_NUMBER_" in account:
del account["ACCOUNT_NUMBER_"]
# Update the 'CASE_NUMBER' field
if account["CASE_NUMBER"] != str(index): # If the CASE_NUMBER is incorrect
updated_count += 1
account["CASE_NUMBER"] = str(index)
# Add the updated account data with the new key to the updated_data dictionary
updated_data[new_key] = account
try:
with open(file_path, "w", encoding="utf-8") as f:
json.dump(updated_data, f, indent=4, ensure_ascii=False)
print(
f"[{get_current_timestamp()}] Successfully saved the corrected data back to the file."
)
except Exception as e:
print(f"[{get_current_timestamp()}] Error saving the file: {e}")
return
print(f"[{get_current_timestamp()}] Found {total_accounts} accounts in the file.")
print(f"[{get_current_timestamp()}] {updated_count} accounts were updated.")
# Run the function on the JSON file
fix_account_numbers("../Database-Files/Edit-Database/Compromised-Discord-Accounts.json")