Skip to content

Instantly share code, notes, and snippets.

@dmoruzzi
Created June 10, 2022 03:00
Show Gist options
  • Save dmoruzzi/865ea4dd11f75dcaab6cbea10848a996 to your computer and use it in GitHub Desktop.
Save dmoruzzi/865ea4dd11f75dcaab6cbea10848a996 to your computer and use it in GitHub Desktop.
Download all Meijer mPerks PDF receipts
import requests
import os
import time
# This should be extracted from your browser session.
cookies = {
"digital-token": "",
"user_state": "",
}
headers = {
"User-Agent": "Mozilla/5.0 (Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0",
"Origin": "https://www.meijer.com",
"Connection": "keep-alive",
}
json_data = {
"fromDate": "2000-01-01",
"toDate": time.strftime("%Y-%m-%dT23:59:59", time.gmtime(time.time() + 60 * 60 * 24 * 365)),
"type": 1,
}
if __name__ == "__main__":
receipt_dic = {}
mperks_json = (requests.post("https://www.meijer.com/bin/meijer/receipts",
cookies=cookies, headers=headers, json=json_data)).json()
if mperks_json:
print("Successfully retrieved receipts IDs from Meijer")
for i in mperks_json["receipts"]:
href = requests.post("https://www.meijer.com/bin/meijer/receipts", cookies=cookies,
headers=headers, data="{receiptId:" + i["receiptId"] + ",formatType:PDF,type:2}").text
receipt_dic[i["receiptId"]] = href[1:-1]
if href:
print(
f"Successfully affiliated receipt {i['receiptId']} with {href[1:-1]}.")
if not os.path.exists("output"):
os.makedirs("output")
print("Successfully created output directory.")
for receipt, href in receipt_dic.items():
with open("output/Meijer_receipt_" + receipt + ".pdf", "wb") as f:
# If the receipt submitted online rather than checkout, the href will be null.
if href:
f.write(requests.get(href).content)
print(f"Receipt {receipt} downloaded.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment