Skip to content

Instantly share code, notes, and snippets.

@stith
Created September 20, 2011 11:49
Show Gist options
  • Save stith/1228923 to your computer and use it in GitHub Desktop.
Save stith/1228923 to your computer and use it in GitHub Desktop.
Convert Essentials warps to CommandBook's CSV
#!/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()
@Natfan
Copy link

Natfan commented Mar 10, 2017

For reference, to use this do:

python ess2cbwarp.py filePath

@Ricki-BumbleDev
Copy link

Ricki-BumbleDev commented Jul 8, 2018

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

  1. Run npm install
  2. Put the Essentials warps in a folder called warps-essentials inside the current working directory
  3. Run node app >warps.csv

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