[MIRROR] Load alien/job whitelists from database, if enabled (#11751)

Co-authored-by: Selis <12716288+ItsSelis@users.noreply.github.com>
Co-authored-by: Kashargul <KashL@t-online.de>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-11-05 02:46:01 -07:00
committed by GitHub
parent a8b89de4fd
commit 3139b7684f
10 changed files with 422 additions and 46 deletions

View File

@@ -0,0 +1,49 @@
input_file = 'config/alienwhitelist.txt'
output_file = 'whitelist.sql'
table_name = 'whitelist'
with open(input_file, 'r', encoding='utf-8') as infile, \
open(output_file, 'w', encoding='utf-8') as outfile:
for line in infile:
line = line.strip()
if not line:
continue
if "#" in line:
print(f"Skipping commented line: {line}")
continue
# Split on ' - ', expecting exactly two parts
parts = line.split(' - ')
if len(parts) != 2:
print(f"Skipping invalid line: {line}")
continue
username, entry = (p.replace("'", "''") for p in parts) # Escape single quotes
kind = "species"
sql = (
f"INSERT INTO {table_name} (ckey, entry, kind) "
f"VALUES ('{username}', '{entry}', '{kind}');\n"
)
outfile.write(sql)
input_file = 'config/jobwhitelist.txt'
with open(input_file, 'r', encoding='utf-8') as infile, \
open(output_file, 'a', encoding='utf-8') as outfile:
for line in infile:
line = line.strip()
if not line:
continue
if "#" in line:
print(f"Skipping commented line: {line}")
continue
# Split on ' - ', expecting exactly two parts
parts = line.split(' - ')
if len(parts) != 2:
print(f"Skipping invalid line: {line}")
continue
username, entry = (p.replace("'", "''") for p in parts) # Escape single quotes
kind = "job"
sql = (
f"INSERT INTO {table_name} (ckey, entry, kind) "
f"VALUES ('{username}', '{entry}', '{kind}');\n"
)
outfile.write(sql)