You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main.py
+10-9Lines changed: 10 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -23,28 +23,29 @@ def readConfig():
23
23
else:
24
24
returnlogging.info(".env file not present, falling back to normal Environment")
25
25
26
-
definit(latitude, longitude):
26
+
definit(latitude, longitude, token):
27
27
'''
28
28
(ab)using the default, and open GraphQL endpoint on ah.nl to extract important information about stores and their whereabouts.
29
29
gql_body is a long graphql string tailored for getting the stores
30
30
'''
31
-
url="https://www.ah.nl/gql"#open gql endpoint for anonymous requests
32
-
headers= {'Client-Name': 'ah-stores','Client-Version':'0.230.0'} #Missing client identification. Requests should include \"client-name\" and \"client-version\" headers
33
-
gql_body="""query stores($filter: StoreFilterInput, $size: PageSize!, $start: Int) {stores(filter: $filter, size: $size, start: $start) { result { ...storeList __typename} page { total hasNextPage __typename} __typename }}fragment storeList on Store { id name storeType phone distance address { ...storeAddress __typename } geoLocation { latitude longitude __typename} openingDays { ...openingDaysInfo __typename } __typename}fragment storeAddress on StoreAddress { city street houseNumber houseNumberExtra postalCode countryCode __typename}fragment openingDaysInfo on StoreOpeningDay { dayName type date openingHour { ...storeOpeningHour __typename } }fragment storeOpeningHour on StoreOpeningHour { date openFrom openUntil __typename}"""
34
-
json_data= {"operationName":"stores","variables":{"filter":{"location":{"latitude":latitude,"longitude":longitude}},"start":0,"size":os.environ['number_of_stores']},"query": gql_body} #tweak size: number of albert heijns this variable is for filtering
31
+
url="https://api.ah.nl/graphql"#open gql endpoint for anonymous requests
32
+
headers= {'Client-Name': 'ah-stores','Client-Version':'0.230.0', "Authorization": "Bearer "+token} #Missing client identification. Requests should include \"client-name\" and \"client-version\" headers
33
+
gql_body="""query storesListResults($filter: StoresFilterInput, $size: PageSize!, $start: Int) {storesSearch(filter: $filter, size: $size, start: $start) { result { ...storesList __typename} pageInfo { total hasNextPage __typename} __typename }}fragment storesList on Stores { id name storeType phone distance address { ...storesAddress __typename } geoLocation { latitude longitude __typename} openingDays { ...openingDaysInfo __typename } __typename}fragment storesAddress on StoresAddress { city street houseNumber houseNumberExtra postalCode countryCode __typename}fragment openingDaysInfo on StoresOpeningDay { dayName type date openingHour { ...storesOpeningHour __typename } }fragment storesOpeningHour on StoresOpeningHour { openFrom openUntil __typename}"""
34
+
json_data= {"operationName":"storesListResults","variables":{"filter":{"location":{"latitude":latitude,"longitude":longitude}},"start":0,"size":os.environ['number_of_stores']},"query": gql_body} #tweak size: number of albert heijns this variable is for filtering
35
35
response=requests.post(url=url, headers=headers, json=json_data, ) #simple post request putting it all together
36
36
37
37
ifresponse.status_code==200:
38
38
storedict= {}
39
39
templist= []
40
40
jsonformatting=json.loads(response.text)
41
-
forxin (jsonformatting["data"]["stores"]["result"]): #json filters for grabbing a couple of important variables
41
+
forxin (jsonformatting["data"]["storesSearch"]["result"]): #json filters for grabbing a couple of important variables
42
42
templist.append(x['name'])
43
43
templist.append(x['address'])
44
44
templist.append(x['distance'])
45
45
foryin (x['openingDays']):
46
-
ify['type'] =="CURRENT":
47
-
templist.append(y['openingHour'])
46
+
foriiny:
47
+
ifi['type'] =="CURRENT":
48
+
templist.append(i['openingHour'])
48
49
storedict[x['id']] =templist
49
50
templist= []
50
51
logging.info(f"Succesful request against graphQL endpoint {url} with {response.status_code}")
@@ -121,7 +122,7 @@ def boxRequests():
121
122
'''
122
123
function where the magic happens: it connects to the local sqlite db, connects authenticated to the surprise-boxes api and executes queries on the database
123
124
'''
124
-
results=init(float(os.environ['latitude']),float(os.environ['longitude'])) #Don't forget to make this a variable / cli parameter
125
+
results=init(float(os.environ['latitude']),float(os.environ['longitude']), accessToken) #Don't forget to make this a variable / cli parameter
0 commit comments