我的艾伯特·海恩图书馆
mijnah的Python项目详细描述
米伊纳
与mijn Albert Heijn V2 API交互
安装
pip install mijnah
使用
推车
AH使用recaptcha令牌进行身份验证,因此传递ah_token
或{
- 在
身份验证:
^{pr2}$ 在 - 在
购物车:
ah.list_cart()
在 - 在
将商品添加到购物车:
ah.add_to_cart(product_id=1234,amount=2)
id可以在产品url中找到。例如,
在https://www.ah.nl/producten/product/wi471282/chatelain-notre-dame-medoc
中的id是471282
。在 - 在
更新购物车:
ah.update_cart(product_id=1234,amount=0)
在 - 在
空车:
ah.empty_cart()
在
产品
- 初始化:
importmijnahp=mijnah.Product(product_id=1234)
在 - 对象属性:
p.idp.namep.categoryp.descriptionp.brandp.price
在
示例
获取购物车总数
importmijnahimportjsonah=mijnah.Cart(ah_token_presumed='ah_token')ah.empty_cart()# add some itemsah.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 invoiceprint(json.dumps([{'product':item['product'].name,'quantity':item['quantity'],'price':item['product'].price,'total':item['quantity']*item['product'].price}foritemincart],indent=2))# Get total itemsprint('total items:',sum(item['quantity']foritemincart))# Get total itemsprint('total price:',sum(item['quantity']*item['product'].priceforitemincart))
[{"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}]totalitems:8totalprice:15.4
变更日志
1.2.0款
- 添加了使用
ah_token
,ah_token_presumed
,或两者都使用的功能。在 - 添加的测试
1.1.0款
- 初始版本
- 项目
标签: