Skip to content

Instantly share code, notes, and snippets.

@ar00n
Created April 27, 2020 14:52
Show Gist options
  • Save ar00n/f1ac69dd52554e56f012c8d631bed5d7 to your computer and use it in GitHub Desktop.
Save ar00n/f1ac69dd52554e56f012c8d631bed5d7 to your computer and use it in GitHub Desktop.
Migrate GriefPrevention from SQL to file directory storage.
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()
@DMessor
Copy link

DMessor commented Dec 7, 2021

Hey, I'm getting this error when using this script:
Traceback (most recent call last):
File "C:\Users\User\Desktop\gp_to_file.py", line 45, in
os.utime(path+"/PlayerData/"+x[0],(time.mktime(x[1].timetuple()), time.mktime(x[1].timetuple())))
OverflowError: mktime argument out of range

Could you help?

@ar00n
Copy link
Author

ar00n commented Dec 8, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment