added one time insert of former bans from file
This commit is contained in:
parent
572d6f4f93
commit
5d6dbc5a70
4
.gitignore
vendored
4
.gitignore
vendored
@ -475,3 +475,7 @@ composer.lock
|
||||
|
||||
##### Project related
|
||||
config.php
|
||||
|
||||
one-time-insertion/venv
|
||||
one-time-insertion/__pycache__
|
||||
one-time-insertion/settings.py
|
||||
|
||||
1117
one-time-insertion/banlist.cfg
Normal file
1117
one-time-insertion/banlist.cfg
Normal file
File diff suppressed because it is too large
Load Diff
38
one-time-insertion/main.py
Executable file
38
one-time-insertion/main.py
Executable file
@ -0,0 +1,38 @@
|
||||
from settings import get_kbans
|
||||
import vdf
|
||||
|
||||
def main():
|
||||
with get_kbans() as conn:
|
||||
with conn.cursor(buffered=True) as cur:
|
||||
t = {}
|
||||
with open("banlist.cfg", encoding="utf-8") as f:
|
||||
t = vdf.load(f)["banlist"]
|
||||
for key, val in t.items():
|
||||
sql_statement = """
|
||||
INSERT INTO knifeban_web.KbRestrict_CurrentBans
|
||||
(client_name, client_steamid, client_ip, admin_name, admin_steamid, reason, `map`, `length`,
|
||||
time_stamp_start, time_played_start, time_played_end, is_expired, is_removed, time_stamp_removed,
|
||||
admin_name_removed, admin_steamid_removed, reason_removed)
|
||||
VALUES('unknown name', %s, 'unknown ip', %s, 'unknown steamID', 'knifebanned', 'unknown map', %s, current_timestamp(), %s, %s, %s, 0, 0, '', '', '');
|
||||
"""
|
||||
admin_name = 'unknown admin'
|
||||
if 'admin' in val: admin_name = val['admin']
|
||||
length = 1
|
||||
if 'duration' in val:
|
||||
length = int(val['duration'])
|
||||
is_expired = 0
|
||||
|
||||
#length 0 means permanent on the webproject but in sourcemod its just saying expired.
|
||||
if length == 0:
|
||||
is_expired = 1
|
||||
length = 1
|
||||
elif length == -1: length = 0
|
||||
time_hour = int(val['time']) / 60
|
||||
time_minutes = int(val['time']) & 60
|
||||
time_played_start = time_hour + time_minutes
|
||||
cur.execute(sql_statement, [key, admin_name, length, time_played_start, time_played_start + length, is_expired])
|
||||
#print(sql_statement)
|
||||
conn.commit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
2
one-time-insertion/requirements.txt
Normal file
2
one-time-insertion/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
vdf
|
||||
mysql-connector-python
|
||||
8
one-time-insertion/settings.py.example
Normal file
8
one-time-insertion/settings.py.example
Normal file
@ -0,0 +1,8 @@
|
||||
import mysql.connector
|
||||
|
||||
def get_kbans():
|
||||
return mysql.connector.connect(
|
||||
host="127.0.0.1",
|
||||
port=3306,
|
||||
user="",
|
||||
password="")
|
||||
Loading…
Reference in New Issue
Block a user