Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save banagale/0d9002f4d80441ab1f3dc8435fe73a09 to your computer and use it in GitHub Desktop.
Save banagale/0d9002f4d80441ab1f3dc8435fe73a09 to your computer and use it in GitHub Desktop.
Finding which Walmart locations nearby have inventory of a product
#!/usr/bin/python3
from datetime import datetime
import click
import requests
from py_imessage import imessage
def build_store_dict(zipcode, n):
url = f'https://www.walmart.com/grocery/v4/api/serviceAvailability?postalCode={zipcode}'
resp = requests.get(url).json()
print(f'Filtering results to the top {n} locations near the zipcode: {zipcode} - {resp["geo"]["city"]}, {resp["geo"]["state"]}...')
stores = {}
for entry in resp['accessPointList'][:n]:
stores[entry["dispenseStoreId"]] = entry['address']['line1']
return stores
@click.command()
@click.option('-p', '--phone', default=None, type=click.Choice(['blake', 'philip']),
help='Phone number to send the notification to')
@click.option('-i', '--item', default='switch', type=click.Choice(['switch', 'joycons', 'ds']),
help='Desired item you are searching for')
@click.option('-z', '--zipcode', default=85140, type=int, help='Desired zipcode you are searching in')
@click.option('-n', default=10, type=int, help='Number of stores in range you would like to search through')
def main(phone, item, zipcode, n):
phone_contacts = {
'person1': "4801234567",
'person2': "4802345678",
}
item_dict = {
'switch': [709776123, 994790027],
'switchs': [709776123, 994790027, 306029956],
'switchlight': [306029956],
'joycons': [656821586, 807408404, 921709016, 55449978],
'ds': [652383534],
}
# list of near by stores
stores = build_store_dict(zipcode, n)
print(datetime.now().strftime("%Y-%m-%d %H:%M"))
for store_id, store_address in stores.items():
for itemId in item_dict[item]:
url = f'https://www.walmart.com/grocery/v3/api/products/{itemId}?itemFields=all&storeId={store_id}'
resp = requests.get(url)
i = resp.json()
if i['basic']['isOutOfStock']:
print(f"Store: {store_id} ({store_address}) does not have {i['basic']['name']} in stock...")
else:
msg = f"Walmart store: {store_id} ({store_address}) IN STOCK! - {i['basic']['name']}"
print(msg)
if phone:
imessage.send(phone_contacts[phone], msg)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment