Last active
April 9, 2019 02:27
-
-
Save ritvikmath/0ca460f885205b13ec31712dcaaf8249 to your computer and use it in GitHub Desktop.
Calling Starbucks Store Locator API for each zip code in LA County
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
| #open zip code file | |
| f = open('laZips.txt', 'r') | |
| laZips = [z.replace('\n','') for z in f.readlines()] | |
| allStores = [] | |
| for idx,z in enumerate(laZips): | |
| #call request for 100 stores with current zipcode | |
| r = requests.get('https://www.starbucks.com/store-locator?place='+z) | |
| #if any response fails, quit immediately | |
| if r.status_code != 200: | |
| raise SystemExit | |
| #process the text response that Starbucks gives back | |
| storeInfoList = processResponse(r.text) | |
| #truncate the returned zip code to a 5 digit zip | |
| for storeInfo in storeInfoList: | |
| storeInfo[6] = storeInfo[6][:5] | |
| #add this store to the master list of stores | |
| allStores += storeInfoList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment