Skip to content

Instantly share code, notes, and snippets.

@kriberg
Last active December 15, 2015 00:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kriberg/abcae71b80213ae36b8f to your computer and use it in GitHub Desktop.
Save kriberg/abcae71b80213ae36b8f to your computer and use it in GitHub Desktop.
This google script macro can be used to import your assets from the eve online api. Combine this with a pivot table to do inventory and make your industry spreadsheet sparkle.
/*
To add this to your spreadsheet, hit Tools -> Script Editor.
Chose spreadsheet in the left column to create a custom function for spreadsheets.
Copypaste this code into the Code.gs file, replacing it's current contents, and
press ctrl-s to save. Then just close the script tab.
Next up, you need to create two sheets for item types and stations. Into these, you import the respective tables
from the current database dump. You can find these from fuzzysteve's dumps at http://www.fuzzwork.co.uk/dump/
Download the stastations and invtypes in the xls.bz2 format. Copy the ID to column A and the name to column B
for both, into their respective sheets. Then mark the columns and add a named data range. Items should be named
"itemData" and stations should be "stationData". If you messed this up, the names wont render and you'll get the
IDs instead.
Create a sheet to hold your assets and put this in row 1 as your column headers:
itemID, typeID, quantity, flag, singleton, rawQuantity, locationID, parent itemID
To import assets, type this into A2:
=assetList("char", "your keyID","your vCode","your characterID")
or this for corporation assets:
=assetList("corp", "your keyID","your vCode","your characterID")
You can also limit the assets to a single station, i.e., where a corp office is, by adding the station name at the end:
=assetList("corp", "your keyID","your vCode","your characterID", "Hek VIII - Moon 12 - Boundless Creation Factory")
You should now get a list which looks something like this:
1009382565994 Condensed Scordite 148 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009383731243 Concentrated Veldspar 184 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009405435677 Massive Scordite 166 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009405956214 Scordite 96 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009406030517 Veldspar 171 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009410116620 Pyroxeres 141 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009460681671 Dense Veldspar 247 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009462856591 Silvery Omber 36 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009463239504 Plagioclase 3 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009463548167 Azure Plagioclase 253 117 0 Nonni IV - Kaalakiota Corporation Factory 264004928
1009484413371 Cap Recharger I Blueprint 1 119 1 -2 Nonni IV - Kaalakiota Corporation Factory 264004928
*/
// globals to avoid stack size roof
var assets = new Array();
function office2station(locationID) {
if(locationID >= 66000000 && locationID <= 66014933)
return locationID-6000001;
if(locationID >= 66014934 && locationID <= 67999999)
return locationID-6000000;
return locationID;
}
function parseAssets(rows, parent, locationID, items, stations, location) {
for(var i = 0; i < rows.length; i++) {
rawQuantity = null;
if(rows[i].getAttribute("locationid")) {
locationID = office2station(parseInt(rows[i].getAttribute("locationid").getValue()));
if(stations) {
var key = "_"+locationID;
if(stations[key])
locationID = stations[key];
}
}
if(location)
if(location != locationID)
continue;
if(rows[i].getAttribute("rawquantity"))
rawQuantity = rows[i].getAttribute("rawquantity").getValue();
var asset = [rows[i].getAttribute("itemid").getValue(),
rows[i].getAttribute("typeid").getValue(),
parseInt(rows[i].getAttribute("quantity").getValue()),
rows[i].getAttribute("flag").getValue(),
rows[i].getAttribute("singleton").getValue(),
rawQuantity,
locationID,
parent];
if(items) {
var key = "_"+asset[1];
if(items[key])
asset[1] = items[key];
}
assets.push(asset);
if(rows[i].getElement("rowset")) {
parseAssets(rows[i].getElement("rowset").getElements("row"),
asset[0],
asset[6],
items,
stations);
}
}
}
function assetList(type, keyID, vCode, characterID, location) {
var url = "https://api.eveonline.com/"+type+"/AssetList.xml.aspx?keyID="+keyID+"&vCode="+vCode+"&characterID="+characterID;
var parameters = {method : "get", payload : ""};
var xmlFeed = UrlFetchApp.fetch(url, parameters).getContentText();
var xml = Xml.parse(xmlFeed, true);
var stations = new Array();
var items = new Array();
var stationRange = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("stationData");
if(stationRange) {
var data = stationRange.getValues();
for(var i = 0; i < data.length; i++) {
var key = "_"+data[i][0];
stations[key] = data[i][1];
}
}
var itemRange = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("itemData");
if(itemRange) {
var data = itemRange.getValues();
for(var i = 0; i < data.length; i++) {
var key = "_"+data[i][0];
items[key] = data[i][1];
}
}
if(xml) {
var rows = xml.getElement().getElement("result").getElement("rowset").getElements("row");
parseAssets(rows, null, null, items, stations, location);
}
return assets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment