Created
December 2, 2014 12:10
-
-
Save aspender/71cb70c6b3b60cdd8936 to your computer and use it in GitHub Desktop.
Check the Apple UK iPhone availability checker for a set of stores and SKUs and sent alerts to Slack when availabile
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
| #!/usr/bin/env python | |
| import urllib2 | |
| import json | |
| # stores and skus found from https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/availability | |
| stores = { | |
| "R245": "Covent Garden", | |
| "R092": "Regent St" | |
| } | |
| skus = { | |
| "MG4F2B/A": "iPhone 6 - Space Grey - 64GB", | |
| "MG4A2B/A": "iPhone 6 - Space Grey - 128GB" | |
| } | |
| availablityurl = "https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/availability.json" | |
| # Create an incoming webhook to @slackbot to send messages to yourself | |
| slackwebhook = "https://hooks.slack.com/services/<your_webhook_here>" | |
| def sendslack(message): | |
| data = json.dumps({"text": message, "username": "iPhone availability"}) | |
| request = urllib2.Request(slackwebhook, data, {'Content-Type': 'application/json'}) | |
| response = urllib2.urlopen(request) | |
| response.close() | |
| def checkstock(store, stockList): | |
| for sku in skus.keys(): | |
| if(stockList.get(sku) == True): | |
| sendslack("{0}: {1} in stock".format(store, skus[sku])) | |
| request = urllib2.Request(availablityurl) | |
| response = urllib2.urlopen(request) | |
| jsonresponse = json.loads(response.read()) | |
| response.close() | |
| for store in stores: | |
| checkstock(stores[store], jsonresponse.get(store)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment