Skip to content

Commit 1463ea8

Browse files
committed
fixed 403 on graphql endpoint
1 parent f377aa3 commit 1463ea8

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ appie.db
33
config.ini
44
.env
55
.gitignore
6+
.venv
67

main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@ def readConfig():
2323
else:
2424
return logging.info(".env file not present, falling back to normal Environment")
2525

26-
def init(latitude, longitude):
26+
def init(latitude, longitude, token):
2727
'''
2828
(ab)using the default, and open GraphQL endpoint on ah.nl to extract important information about stores and their whereabouts.
2929
gql_body is a long graphql string tailored for getting the stores
3030
'''
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
3535
response = requests.post(url=url, headers=headers, json=json_data, ) #simple post request putting it all together
3636

3737
if response.status_code == 200:
3838
storedict = {}
3939
templist = []
4040
jsonformatting = json.loads(response.text)
41-
for x in (jsonformatting["data"]["stores"]["result"]): #json filters for grabbing a couple of important variables
41+
for x in (jsonformatting["data"]["storesSearch"]["result"]): #json filters for grabbing a couple of important variables
4242
templist.append(x['name'])
4343
templist.append(x['address'])
4444
templist.append(x['distance'])
4545
for y in (x['openingDays']):
46-
if y['type'] == "CURRENT":
47-
templist.append(y['openingHour'])
46+
for i in y:
47+
if i['type'] == "CURRENT":
48+
templist.append(i['openingHour'])
4849
storedict[x['id']] = templist
4950
templist = []
5051
logging.info(f"Succesful request against graphQL endpoint {url} with {response.status_code}")
@@ -121,7 +122,7 @@ def boxRequests():
121122
'''
122123
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
123124
'''
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
125126
sqliteConnection = sqlite3.connect('appie.db')
126127
cursor = sqliteConnection.cursor()
127128
for key,value in results.items():

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $ git clone https://github.com/TobiasS1402/appiesniper
8181
$ cd appiesniper
8282

8383
# Install dependencies
84-
$ pip -r install requirements.txt
84+
$ pip install -r requirements.txt
8585

8686
# Customise environment variables
8787
$ cp .env.example .env

0 commit comments

Comments
 (0)