Skip to main content

mijn albert heijn library

Project description

mijnah

Interact with mijn Albert Heijn V2 API

Usage

Cart

AH uses a recaptcha token to authenticate, so it's easier to pass cookie tokens: ah_token, ah_token_presumed.

  • Authentication:

    import mijnah
    ah = mijnah.Cart(ah_token="my-ah-token", ah_token_presumed="my-ah-token-presumed")
    
  • List cart:

    ah.list_cart()
    
  • Add item to cart:

    ah.add_to_cart(product_id=1234, amount=2)
    

    The id can be found in the product url. For example the id in https://www.ah.nl/producten/product/wi471282/chatelain-notre-dame-medoc is 471282.

  • Update cart:

    ah.update_cart(product_id=1234, amount=0)
    
  • Empty cart:

    ah.empty_cart()
    

Product

  • Initialize:
    import mijnah
    p = mijnah.Product(product_id=1234)
    
  • Object properties:
    p.id
    p.name
    p.category
    p.description
    p.brand
    p.price
    

Example

Getting cart totals

import mijnah
import json
ah = mijnah.Cart(ah_token='ah_token',
                 ah_token_presumed='ah_token_presumed')
ah.empty_cart()
# add some items
ah.add_to_cart(product_id=168153, amount=2)
ah.add_to_cart(product_id=224710, amount=1)
ah.add_to_cart(product_id=129138, amount=3)
ah.add_to_cart(product_id=198412, amount=2)
cart = ah.list_cart()
# Generate invoice
print(json.dumps([
    {
        'product': item['product'].name,
        'quantity': item['quantity'],
        'price': item['product'].price,
        'total': item['quantity'] * item['product'].price
    } for item in cart], indent=2))
# Get total items
print('total items:', sum(item['quantity'] for item in cart))
# Get total items
print('total price:', sum(
    item['quantity']*item['product'].price for item in cart))
[
  {
    "product": "AH IJsbergsla voordeel",
    "quantity": 2,
    "price": 1.79,
    "total": 3.58
  },
  {
    "product": "AH Babyspinazie",
    "quantity": 1,
    "price": 1.59,
    "total": 1.59
  },
  {
    "product": "AH Frambozen",
    "quantity": 3,
    "price": 2.39,
    "total": 7.17
  },
  {
    "product": "Valle del sole Popcorn ma\u00efs",
    "quantity": 2,
    "price": 1.53,
    "total": 3.06
  }
]
total items: 8
total price: 15.4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mijnah-1.0.1.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file mijnah-1.0.1.tar.gz.

File metadata

  • Download URL: mijnah-1.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for mijnah-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a7c062e37be4b0e5e5ed32c8bd8eb320b274b91b99e18c6d3e29cb35afe7f08e
MD5 a6bddd5f689a0a9eca7a5bdb7d483fd8
BLAKE2b-256 bc4a12f06b79d46b18deb716fb509d5084b3f1324c1ebd8efbb6111381d7d819

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page