-
-
Save jaronheard/8d11bcf1942510eb0213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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