Skip to content

Instantly share code, notes, and snippets.

@jaronheard
Forked from Bachmann1234/check.js
Last active August 29, 2015 14:19
Show Gist options
  • Save jaronheard/8d11bcf1942510eb0213 to your computer and use it in GitHub Desktop.
Save jaronheard/8d11bcf1942510eb0213 to your computer and use it in GitHub Desktop.
var ITEMS_TO_CHECK = [
"20265396",
"50265682",
"90265388",
"90265388",
"80265666",
"80265666",
"90265388",
"20265631",
"204648",
"90265468",
"50266549",
"60265460",
"10266532",
"90265468",
"50266549",
"40266408",
"60241822",
"80266411"
];
var PORTLAND_STORE_CODE = "211";
var AVAILABILITY_URL = "http://www.ikea.com/us/en/iows/catalog/availability/";
function checkAllItems() {
var existingItems = ITEMS_TO_CHECK.filter(checkItem);
if(existingItems.length > 0) {
GmailApp.sendEmail("__", "Ikea items in stock", existingItems.join(", "));
}
}
function checkItem(item) {
var avaliabilityDataXML = XmlService.parse(UrlFetchApp.fetch(AVAILABILITY_URL + item))
var yourStoreData = avaliabilityDataXML.getRootElement()
.getChild("availability")
.getChildren()
.filter(function(child) {
return child.getAttribute("buCode") == "[buCode='" + STOUGHTON_STORE_CODE + "']";
})[0];
return yourStoreData.getChild("stock").getChild("availableStock").getText() > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment