1
0
Fork 0

Add script to migrate player data to SQLite

Requires the json and sqlite3 modules. I think these are installed by
default, but don't quote me on that.
This commit is contained in:
Ryan Fox 2020-10-25 15:59:45 +00:00
parent a0c50e0fb0
commit 67f9bb49c0
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
1 changed files with 14 additions and 0 deletions

14
scripts/migrate_players.py Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env python3
import json
import sqlite3
with open("2a03.json", "r") as f:
config = json.loads(f.read())
sql = "INSERT INTO players (uuid, home) VALUES "
def sql_values(player):
return "('"+player["uuid"]+"', '"+json.dumps(player["home"])+"')"
sql += ", ".join(list(map(sql_values, config["members"])))
sql += ";"
conn = sqlite3.connect("2a03.db")
conn.execute(sql)
conn.commit()
conn.close()