Created
September 20, 2011 08:49
-
-
Save stith/1228674 to your computer and use it in GitHub Desktop.
Convert Essentials homes to SpawnControl
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
#!/usr/bin/env python | |
import sys | |
import sqlite3 | |
import yaml | |
import os | |
import time | |
from os import path | |
# Make sure paths exist | |
if len(sys.argv) != 2: | |
print "Usage: %s pluginpath" % (sys.argv[0]) | |
sys.exit() | |
pluginDir = sys.argv[1] | |
if not path.exists(pluginDir): | |
print "Path %s doesn't exist" % (pluginDir) | |
sys.exit() | |
essentialsDir = path.join(pluginDir,'Essentials') | |
scDir = path.join(pluginDir,'SpawnControl') | |
if not path.exists(essentialsDir): | |
print "Essentials path %s doesn't exist" % essentialsDir | |
sys.exit() | |
if not path.exists(scDir): | |
print "SpawnControl path % doesn't exist" % scDir | |
sys.exit() | |
userdir = path.join(essentialsDir,'userdata') | |
if not path.exists(userdir): | |
print "Can't find essentials userdata directory" | |
sys.exit() | |
# Connect to DB and start the loop | |
scdb = sqlite3.connect(path.join(scDir,'spawncontrol.db')) | |
c = scdb.cursor() | |
userfiles = os.listdir(userdir) | |
for userfile in userfiles: | |
user = open(path.join(userdir,userfile)) | |
useryaml = yaml.load(user) | |
if not useryaml or 'home' not in useryaml: | |
continue | |
print "Adding %s's home" % userfile[0:-4] | |
for world in useryaml["home"]["worlds"]: | |
h = useryaml["home"]["worlds"][world] | |
c.execute('insert into players (name, world, x, y, z, r, p, updated, updated_by) values (?, ?, ?, ?, ?, ?, ?, ?, ?)',(userfile[0:-4], world, h["x"],h["y"],h["z"],h["yaw"],h["pitch"],int(time.time()),"Essentials Import")) | |
user.close() | |
scdb.commit() | |
c.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment