Created
April 5, 2015 00:19
-
-
Save Bachmann1234/ba82080a5016191d949e to your computer and use it in GitHub Desktop.
IKEA stock check
This file contains hidden or 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 = [ | |
"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