1+ import json
2+ import os
3+ import time
4+ from datetime import datetime
5+
6+
7+ def convert_date_to_epoch (date_str ):
8+ """Convert a date string in YYYY-MM-DD format to epoch timestamp."""
9+ try :
10+ dt = datetime .strptime (date_str , "%Y-%m-%d" )
11+ return int (dt .timestamp ())
12+ except ValueError :
13+ # Return current timestamp if date format is invalid
14+ return int (time .time ())
15+
16+
17+ def main ():
18+ # Define file paths
19+ compromised_file = "../Database-Files/Main-Database/Compromised-Discord-Accounts.json"
20+ filter_file = "../Database-Files/Filter-Database/Discord-IDs.json"
21+
22+ # Check if files exist
23+ if not os .path .exists (compromised_file ):
24+ print (f"Error: Compromised accounts file not found at { compromised_file } " )
25+ return
26+
27+ # Load the compromised accounts data
28+ try :
29+ with open (compromised_file , 'r' , encoding = 'utf-8' ) as f :
30+ compromised_data = json .load (f )
31+ print (f"Successfully loaded compromised accounts data ({ len (compromised_data )} entries)" )
32+ except json .JSONDecodeError as e :
33+ print (f"Error: Failed to parse compromised accounts file: { e } " )
34+ return
35+ except Exception as e :
36+ print (f"Error: Failed to load compromised accounts file: { e } " )
37+ return
38+
39+ # Load the existing filter data if it exists
40+ filter_data = {}
41+ if os .path .exists (filter_file ):
42+ try :
43+ with open (filter_file , 'r' , encoding = 'utf-8' ) as f :
44+ filter_data = json .load (f )
45+ print (f"Successfully loaded existing filter data ({ len (filter_data )} entries)" )
46+ except json .JSONDecodeError :
47+ print (f"Warning: Filter file exists but is not valid JSON, will create new file" )
48+ except Exception as e :
49+ print (f"Error: Failed to load filter file: { e } " )
50+ return
51+
52+ # Counter for new entries
53+ new_entries = 0
54+
55+ # Process each account in the compromised data
56+ for account_key , account_info in compromised_data .items ():
57+ discord_id = account_info .get ("DISCORD_ID" , "" )
58+
59+ # Skip if discord ID is empty or already in filter data
60+ if not discord_id or discord_id in filter_data :
61+ continue
62+
63+ # Determine the TYPE based on ACCOUNT_STATUS
64+ account_status = account_info .get ("ACCOUNT_STATUS" , "" ).upper ()
65+ if account_status == "OPERATIONAL" :
66+ account_type = "THREAT"
67+ elif account_status == "COMPROMISED" :
68+ account_type = "USER"
69+ elif account_status == "DELETED" :
70+ account_type = "DELETED"
71+ else :
72+ account_type = "UNKNOWN"
73+
74+ # Convert found date to epoch time
75+ found_on_date = account_info .get ("FOUND_ON" , "" )
76+ epoch_time = convert_date_to_epoch (found_on_date )
77+
78+ # Add to filter data
79+ filter_data [discord_id ] = {
80+ "FOUND_ON" : epoch_time ,
81+ "TYPE" : account_type
82+ }
83+
84+ new_entries += 1
85+
86+ # Save the updated filter data
87+ try :
88+ with open (filter_file , 'w' , encoding = 'utf-8' ) as f :
89+ json .dump (filter_data , f , indent = 4 )
90+ print (f"Successfully saved filter data with { new_entries } new entries" )
91+ except Exception as e :
92+ print (f"Error: Failed to save filter file: { e } " )
93+ return
94+
95+ print (f"Process completed: { new_entries } new Discord IDs added to filter database" )
96+
97+
98+ if __name__ == "__main__" :
99+ main ()
0 commit comments