Created
April 27, 2020 14:52
-
-
Save ar00n/f1ac69dd52554e56f012c8d631bed5d7 to your computer and use it in GitHub Desktop.
Migrate GriefPrevention from SQL to file directory storage.
This file contains 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() |
Author
ar00n
commented
Dec 8, 2021
via email
•
Check the answer at
https://stackoverflow.com/questions/2518706/python-mktime-overflow-error it
seems one of the entries it's attempting to convert is before Unix time was
created (less than 0) or after like 2040 the year or whatever (when Unix time
integer will be over the possible limit).
…On Tue, 7 Dec 2021, 23:23 DMessor, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/f1ac69dd52554e56f012c8d631bed5d7#gistcomment-3987623>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHEED32Y2QTAEBA5SZ3B3N3UP2JPBANCNFSM5AUGHWFA>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment