Skip to content

Instantly share code, notes, and snippets.

@darvid
Created June 29, 2021 01:21
Show Gist options
  • Save darvid/53941bcee75e643f1538b7359a42667a to your computer and use it in GitHub Desktop.
Save darvid/53941bcee75e643f1538b7359a42667a to your computer and use it in GitHub Desktop.
poe.ninja API integration for LED tickers

Use Google Apps Script to create a web service, plop this in, and deploy. You will need to authorize permissions and allow "Anyone" to access the API. (Nothing sensitive is served by this app, obviously; it's just pulling poe.ninja data. Your LED ticker needs to be able to access it, though.)

To hook it up to your LED ticker, go to its settings page, enable Custom API, and enter the following values:

  • ensure https is checked
  • host: script.google.com
  • path: /macros/s/xxx/exec

Replace the xxx in the path field with your deployment ID from Google Apps Script.

Currently, only two pages of data are shown, with room for 3 lines of items. You can tweak the top of the file to change what's displayed without having to rewrite/refactor any code.

Follow the instructions at LEDTickers if you want to make any changes involving the response data.

var tickerMeta = {
Currency: {
show: ["Mirror of Kalandra", "Exalted Orb"],
},
DivinationCard: {
show: ["House of Mirrors", "The Doctor", "The Nurse"],
}
};
shortNames = {
"Mirror of Kalandra": "Mirror",
"Exalted Orb": "Exalted",
"The Doctor": "Doctor",
"House of Mirrors": "HoM",
"The Nurse": "Nurse",
};
function buildTicker(line, size = 1, startX = 0, startY = 7) {
var result = [];
var name = "currencyTypeName" in line ? line.currencyTypeName : line.name;
var nameObj = {
text: name in shortNames ? shortNames[name] : name,
color: 'FFFFFF',
align: 'L',
size: size,
x: startX,
y: startY,
};
var value;
if ("exaltedValue" in line) {
value = `${line.exaltedValue} ex`;
} else {
var chaos = line.chaosValue || line.chaosEquivalent;
value = `${chaos} c`;
}
var valueObj = {
text: value,
color: 'FFFFFF',
align: 'R',
size: size,
x: 63,
y: startY,
};
var sparkline = "receiveSparkLine" in line ? line.receiveSparkLine : line.sparkline;
if (sparkline !== undefined) {
if (sparkline.totalChange > 0) {
valueObj.color = '00FF00';
} else {
valueObj.color = 'FF0000';
}
}
result.push(nameObj);
result.push(valueObj);
return result;
}
function getOverview(overviewType, league, dataType) {
const url = `https://poe.ninja/api/data/${overviewType}?league=${league}&type=${dataType}`;
var response = UrlFetchApp.fetch(url);
var responseJSON = JSON.parse(response.getContentText());
var page = [];
var x = 0;
var y = 7;
for (let line of responseJSON.lines) {
var meta = tickerMeta[dataType];
for (let name of meta.show) {
if (line.currencyTypeName == name || line.name == name) {
for (let o of buildTicker(line, 1, x, y)) {
page.push(o);
}
y += 7;
}
}
}
return [page];
}
function doGet(e) {
var currencyTickers = getOverview("currencyoverview", "Ultimatum", "Currency");
var divinationTickers = getOverview("itemoverview", "Ultimatum", "DivinationCard");
var JSONString = JSON.stringify(currencyTickers.concat(divinationTickers));
var JSONOutput = ContentService.createTextOutput(JSONString);
JSONOutput.setMimeType(ContentService.MimeType.JSON);
return JSONOutput;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment