Created
November 3, 2014 23:15
-
-
Save mbmccormick/c0de323bce4846a5c6c0 to your computer and use it in GitHub Desktop.
Webscript for tracking the stock status of a product at the Microsoft Store. When scheduled as a cron job, this will send a text message when an item becomes available nearby.
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
local sku = '309986300' | |
local zipcode = '10001' | |
local response = http.request { | |
url = 'https://rtgliveservices.cloudapp.net/Location/LocationService.svc/NearestSites?zipcode=' .. zipcode .. '&maxRadius=100' | |
} | |
local data = json.parse(response.content) | |
local sites = {} | |
for key1, value1 in pairs(data.result) do | |
table.insert(sites, value1.SiteId) | |
end | |
local query = '' | |
for i = 1, # sites do | |
if i > 1 then | |
query = query .. '+OR+' | |
end | |
query = query .. 'SiteId+eq+' .. sites[i] | |
end | |
local response = http.request { | |
url = 'http://rtgliveservices.cloudapp.net/Location/LocationService.svc/sites?filter=' .. query | |
} | |
local data = json.parse(response.content) | |
local stores = {} | |
for key1, value1 in pairs(data.result) do | |
table.insert(stores, value1) | |
end | |
local response = http.request { | |
url = 'http://rtgcatalogservices.cloudapp.net/Catalog.svc/StoreInventory?$format=json&$filter=ProductID+eq+' .. sku | |
} | |
local data = json.parse(response.content) | |
for key1, value1 in pairs(data.value) do | |
if value1.InventoryLevel == 'IN_STOCK' then | |
for i = 1, # stores do | |
if stores[i].StoreNumber == value1.StoreID:gsub('W', '0') then | |
alert.sms('SKU ' .. sku .. ' is now in stock at ' .. stores[i].Address .. ' in ' .. stores[i].Name .. '.') | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment