Skip to content

Instantly share code, notes, and snippets.

@xssfox
Created July 11, 2022 02:01
Show Gist options
  • Save xssfox/981054b5c1f6c0ba4fbd21f9053447cb to your computer and use it in GitHub Desktop.
Save xssfox/981054b5c1f6c0ba4fbd21f9053447cb to your computer and use it in GitHub Desktop.
from urllib.request import urlopen, Request
import json
URL = "https://api.ingka.ikea.com/cia/availabilities/ru/au?itemNos=10373589&expand=StoresList,Restocks,SalesLocations"
SMOL = "https://api.ingka.ikea.com/cia/availabilities/ru/au?itemNos=00540664&expand=StoresList,Restocks,SalesLocations"
stores = {
"557" : {
"name": "Adelaide"
},
"451": {
"name": "Canberra"
},
"919": {
"name": "Logan"
},
"377": {
"name": "Marsden Park"
},
"460": {
"name": "North Lakes"
},
"556": {
"name": "Perth"
},
"385":{
"name": "Rhodes"
},
"384": {
"name": "Richmond"
},
"006": {
"name": "Springvale"
},
"446": {
"name": "Tempe"
}
}
def handler(event, context):
ikea = Request(URL)
ikea.add_header("Accept", "application/json;version=2")
ikea.add_header("Origin", "https://www.ikea.com")
ikea.add_header("Host", "api.ingka.ikea.com")
ikea.add_header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15")
ikea.add_header("Referer","https://www.ikea.com/")
ikea.add_header("X-Client-ID","b6c117e5-ae61-4ef5-b4cc-e0b1e37f0631")
ikea_smol = Request(SMOL)
ikea_smol.add_header("Accept", "application/json;version=2")
ikea_smol.add_header("Origin", "https://www.ikea.com")
ikea_smol.add_header("Host", "api.ingka.ikea.com")
ikea_smol.add_header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15")
ikea_smol.add_header("Referer","https://www.ikea.com/")
ikea_smol.add_header("X-Client-ID","b6c117e5-ae61-4ef5-b4cc-e0b1e37f0631")
data = urlopen(ikea).read().decode("utf-8")
data_smol = urlopen(ikea_smol).read().decode("utf-8")
data = json.loads(data)
data_smol = json.loads(data_smol)
for av in data["availabilities"]:
try:
qty = av["buyingOption"]["cashCarry"]["availability"]["quantity"]
store = av['classUnitKey']['classUnitCode']
stores[store]["qty"] = qty
except KeyError:
pass
for av in data_smol["availabilities"]:
try:
qty = av["buyingOption"]["cashCarry"]["availability"]["quantity"]
store = av['classUnitKey']['classUnitCode']
stores[store]["qty-smol"] = qty
except KeyError:
pass
print(json.dumps(stores))
return {
"body": json.dumps(stores),
"isBase64Encoded": False,
"statusCode": 200,
"headers": {
"content-type": "application/json"
}
}
if __name__ == "__main__":
print(handler({},{}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment