-
-
Save RoboMWM/7d7554e7ae12cbb60272e075f6b82d9d to your computer and use it in GitHub Desktop.
Migrate GriefPrevention from SQL to file directory storage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mysql.connector | |
import os, sys | |
from datetime import datetime | |
import time | |
path = "GriefPreventionData"+time.strftime("%Y%m%d-%H%M%S") | |
try: | |
os.mkdir(path) | |
os.mkdir(path+"/PlayerData") | |
os.mkdir(path+"/ClaimData") | |
except OSError: | |
print ("Creation of the directory failed") | |
sys.exit(0) | |
mydb = mysql.connector.connect( | |
host="localhost", | |
user="USERNAME", | |
passwd="PASSWORD", | |
database="DB_NAME" | |
) | |
def uuidToList(sqlResult): | |
if sqlResult != "": | |
users = sqlResult.split(";") | |
del users[-1] | |
usersString = "\n" | |
for f in users: | |
usersString += "- " + f + "\n" | |
return usersString | |
else: | |
return " []\n" | |
mycursor = mydb.cursor() | |
mycursor.execute("SELECT * FROM griefprevention_playerdata") | |
myresult = mycursor.fetchall() | |
for x in myresult: | |
f = open(path+"/PlayerData/"+x[0], "w") | |
f.write("\n"+str(x[2])+"\n"+str(x[3])+"\n\n") | |
f.close() | |
os.utime(path+"/PlayerData/"+x[0],(time.mktime(x[1].timetuple()), time.mktime(x[1].timetuple()))) | |
mycursor.execute("SELECT * FROM griefprevention_claimdata") | |
myresult = mycursor.fetchall() | |
for x in myresult: | |
f = open(path+"/ClaimData/"+str(x[0])+".yml", "w") | |
if x[8] == 0: | |
inheritNothing = "false" | |
else: | |
inheritNothing = "true" | |
f.write("Lesser Boundary Corner: "+x[2]+"\nGreater Boundary Corner: "+x[3]+"\nOwner: "+x[1]+"\nBuilders:"+uuidToList(x[4])+"Containers:"+uuidToList(x[5])+"Accessors:"+uuidToList(x[6])+"Managers:"+uuidToList(x[7])+"Parent Claim ID: "+str(+x[9])+"\ninheritNothing: "+inheritNothing+"\n") | |
f.close() | |
mycursor.execute("SELECT * FROM griefprevention_nextclaimid") | |
myresult = mycursor.fetchone() | |
f = open(path+"/ClaimData/_nextClaimID", "w") | |
f.write(str(myresult[0])) | |
f.close() | |
mycursor.execute("SELECT * FROM griefprevention_schemaversion") | |
myresult = mycursor.fetchone() | |
f = open(path+"/_schemaVersion", "w") | |
f.write(str(myresult[0])) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment