Skip to content

Instantly share code, notes, and snippets.

@Bachmann1234
Created April 5, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Bachmann1234/ba82080a5016191d949e to your computer and use it in GitHub Desktop.
Save Bachmann1234/ba82080a5016191d949e to your computer and use it in GitHub Desktop.
IKEA stock check
var ITEMS_TO_CHECK = [
"S49022524",
"S99022526",
"S59022528",
"S19022530",
"S79022532",
"S39022534",
"S49022538",
"S09022540"
];
var STOUGHTON_STORE_CODE = "158";
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