Skip to content

Commit d44dfbb

Browse files
author
George Hafiz
committed
Warn if store is unavailable for delivery and display opening hours (Closes issue #4)
1 parent cdd37dc commit d44dfbb

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ async def main():
145145
}])
146146
store_id = [x['storeId'] for x in delivery_stores if x['storeLocation']['address1'] == store_address['address1']][0]
147147

148+
availability = await api.get_store_availability(store_id)
149+
if not availability['availableForDelivery']:
150+
print(f"WARNING: Delivery not possible right now - these are the opening hours:")
151+
opening_hours = await api.get_store_opening_hours(store_id)
152+
for day in opening_hours:
153+
print(f"{day['dayOfWeek']}: {day['storeOpenTime']} - {day['storeCloseTime']}")
154+
148155
store_deals = await api.get_store_deals(store_id)
149156
store_deal = prompt(questions=[{
150157
'type': 'list',

papajohns/api.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import asyncio
66

7+
78
class Api:
89
def __init__(self):
910
self.addresses = None
@@ -24,15 +25,25 @@ async def get_addresses(self, postcode):
2425

2526
async def get_delivery_stores(self, full_address):
2627
stores_results = await self.fetch(['v2', 'stores'], params={'searchType': 'ALL', 'locationType': 'HOME',
27-
'street': full_address['address1'],
28-
'city': full_address['city'],
28+
# 'street': full_address['address1'],
29+
# 'city': full_address['city'],
2930
'postalCode': full_address['postalCode']})
3031
return stores_results['data']['deliveryStores']
3132

33+
async def get_store_availability(self, store_id):
34+
availability = await self.fetch(['v2', 'stores', store_id, 'availability'])
35+
return availability['data']
36+
37+
async def get_store_opening_hours(self, store_id):
38+
opening_hours = await self.fetch(['v2', 'stores', store_id])
39+
return opening_hours['data']['storeHours']
40+
3241
async def get_store_deals(self, store_id):
3342
r = await self.fetch(['v2', 'stores', store_id, 'deals', 'grouped'], params={'hideSteps': 'true'})
3443
return r['data']['deals']
3544

45+
46+
3647
async def check_response(self, resp):
3748
if resp['data']:
3849
return resp

0 commit comments

Comments
 (0)