Last active
December 24, 2015 14:39
-
-
Save binarymatt/6814187 to your computer and use it in GitHub Desktop.
check for iphone 5s
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
| import requests | |
| parts = { | |
| 'GRAY': 'ME344LL/A', | |
| 'SILVER': 'ME345LL/A' | |
| } | |
| url_template = 'http://store.apple.com/us/retail/availabilitySearch?parts.0={}&zip={}' | |
| def send_notice(): | |
| pass | |
| def status(pickup): | |
| if 'unavailable' in pickup: | |
| return '[NO]' | |
| else: | |
| return '[YES]' | |
| def parse_store(store): | |
| part = store['partsAvailability'].keys()[0] | |
| seperator = '\t\t' | |
| if len(store['storeName']) > 16: | |
| seperator = '\t' | |
| print store['storeName'], seperator, status(store['partsAvailability'][part]['pickupDisplay']) | |
| def show_availability(response_dict, count=2): | |
| stores = response_dict['body']['stores'] | |
| map(parse_store, stores[:count]) | |
| if __name__ == "__main__": | |
| for k, v in parts.items(): | |
| print k | |
| print '----------------------------' | |
| url = url_template.format(v, '37220') | |
| response = requests.get(url) | |
| if response.ok: | |
| show_availability(response.json) | |
| print '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment