Skip to content

Instantly share code, notes, and snippets.

@ritvikmath
Last active April 9, 2019 02:27
Show Gist options
  • Select an option

  • Save ritvikmath/0ca460f885205b13ec31712dcaaf8249 to your computer and use it in GitHub Desktop.

Select an option

Save ritvikmath/0ca460f885205b13ec31712dcaaf8249 to your computer and use it in GitHub Desktop.
Calling Starbucks Store Locator API for each zip code in LA County
#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