Created
September 20, 2011 11:49
-
-
Save stith/1228923 to your computer and use it in GitHub Desktop.
Convert Essentials warps to CommandBook's CSV
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 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') | |
cbDir = path.join(pluginDir,'CommandBook') | |
if not path.exists(essentialsDir): | |
print "Essentials path %s doesn't exist" % essentialsDir | |
sys.exit() | |
if not path.exists(cbDir): | |
print "CommandBook path % doesn't exist" % cbDir | |
sys.exit() | |
cbwarpfile = open(path.join(cbDir,'warps.csv'),"w") | |
if not cbwarpfile: | |
print "Couldn't open CommandBook warp file" | |
sys.exit() | |
warpdir = path.join(essentialsDir,'warps') | |
if not path.exists(warpdir): | |
print "Can't find essentials warp directory" | |
sys.exit() | |
warpfiles = os.listdir(warpdir) | |
linestoadd = [] | |
for warpfile in warpfiles: | |
warp = open(path.join(warpdir,warpfile)) | |
w = yaml.load(warp) | |
print "Adding warp %s" % warpfile[0:-4] | |
if not w: | |
continue | |
# name, world, addedby, x, y, z, pitch, yaw | |
linestoadd.append('"%s","%s","%s","%s","%s","%s","%s","%s"\n' % (w['name'], w['world'], 'EssentialsImport', w['x'], w['y'], w['z'], w['pitch'], w['yaw'])) | |
warp.close() | |
cbwarpfile.writelines(linestoadd) | |
cbwarpfile.close() |
For reference, to use this do:
python ess2cbwarp.py filePath
I built the same thing with Node.js:
package.json
{
"name": "warpconverter",
"version": "0.1.0",
"description": "",
"main": "app.js",
"author": "BumbleDev",
"dependencies": {
"csv": "^3.1.0",
"js-yaml": "^3.12.0"
}
}
app.js
const fs = require('fs');
const yaml = require('js-yaml');
const csv = require('csv');
var csvData = [];
fs.readdirSync('warps-essentials').forEach(file => {
var data = fs.readFileSync('warps-essentials/' + file, 'utf8');
var yamlData = yaml.safeLoad(data)
csvData.push({
name: yamlData.name,
world: yamlData.world,
description: '',
x: yamlData.x,
y: yamlData.y,
z: yamlData.z,
pitch: yamlData.pitch,
yaw: yamlData.yaw
});
})
csv.stringify(csvData, (err, data) => {
console.log(data);
});
How to use
- Run
npm install
- Put the Essentials warps in a folder called
warps-essentials
inside the current working directory - Run
node app >warps.csv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I use this?