Last active
September 18, 2016 05:22
-
-
Save roadmapper/8f59b2bda92ff3332aaa556645b40a96 to your computer and use it in GitHub Desktop.
Check all zip codes for availability of an Apple product
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
#!/usr/bin/python | |
import os | |
import sys | |
import json | |
import requests | |
import time | |
import urllib | |
cities = [] | |
print "opening JSON" | |
with open('zips.json') as data_file: | |
cities = json.load(data_file) | |
model = "MNPW2LL/A" | |
model_encoded = urllib.quote(model, '') | |
url = "http://www.apple.com/shop/retail/pickup-message?parts.0=" + model_encoded + "&location=" | |
stores_with_product = [] | |
print "iterating through JSON" | |
for city in cities: | |
r = requests.get(url + city["_id"]) | |
response = json.loads(r.text) | |
print "trying: " + city["_id"] | |
if "stores" in response["body"]: | |
for store in response["body"]["stores"]: | |
if store["partsAvailability"][model]["pickupDisplay"] == "available": | |
store_str = store["storeName"] + ", " + store["city"] + ", " + store["state"] | |
print store_str | |
stores_with_product.append(store_str) | |
for store in stores_with_product: | |
print store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment