In [20]:
import datetime as dt
from collections import OrderedDict
from pathlib import Path
import sys
import os

import requests
from dotenv import load_dotenv, find_dotenv
import yagmail

ROOT = Path('../')
DATA_DIR = ROOT/'tests'/'data'
OUT_DIR = ROOT/'output'

sys.path.append(str(ROOT))

%load_ext autoreload
%autoreload 2

import countdowner as cd

load_dotenv(find_dotenv())


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload
Out[20]:
True

In [31]:
import titlecase as tc

tc.titlecase("hello frei")


Out[31]:
'Hello Frei'

In [32]:
stock_code = 281809
stock_code = 32467
r = cd.get_product(stock_code)
cd.parse_product(r)


Out[32]:
{'stock_code': '32467',
 'name': 'Green & Blacks Chocolate Block Dark 85% Cocoa',
 'description': "Passionately crafted by bringing together the finest ingredients, green & black's offers a distinctively delicious, smooth chocolate experience. Green symbolises our commitment to ethically sourced cocoa, & black stands for the high quality and delicious taste of our chocolate, for pure chocolate pleasure. Green & black's organic 85% dark chocolate is made with a generous measure of madagascan vanilla to balance the bitter notes of the cocoa, creating chocolate that is intense and smooth.",
 'size': '90g',
 'unit_price_($)': 3.33,
 'unit_size': '100G',
 'sale_price_($)': 3.0,
 'price_($)': 3.8,
 'discount_(%)': 21.1,
 'datetime': '2020-06-19T15:13:41'}

In [33]:
r.json()["price"]


Out[33]:
{'originalPrice': 3.8,
 'salePrice': 3.0,
 'savePrice': 0.8,
 'hasBonusPoints': False,
 'isClubPrice': False,
 'isSpecial': True,
 'isNew': False,
 'canShowOriginalPrice': True,
 'discount': None,
 'total': None}

In [16]:
url = f"https://shop.countdown.co.nz/api/v1/products/{stock_code}"
headers = {
#    "content-type": "application/json",
#    "accept": "application/json, text/plain, */*",
#    "referrer": f"https://shop.countdown.co.nz/shop/productdetails?stockcode={stock_code}",
#    "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36",
#     "cookie": "ASP.NET_SessionId=4jvrbqw51xkno2z0grwq1lop; cw-laie=51e20fecf5a747429dfc7c2cb60663ac; __RequestVerificationToken=9ROhr4_9QAmfQjR2yEVPQu1EqVhDjZGHkQ0Mc9hoW3df-PHwN87UHKIfb0RQ2C7AaJ2UWfQG0xLvAMZmltO_SijcHZcqlbGr9xIBWbEnx1U1; cw-next=next; gig_bootstrap_3_PWTq_MK-V930M4hDLpcL_qqUx224X_zPBEZ8yJeX45RHI-uKWYQC5QadqeRIfQKB=login_ver3; ARRAffinity=c2dba6f1a343c8b908c4c09af49d7b98f09d8a609f95e791c930db34ec6d2ef1; ai_user=l17Us|2020-06-16T08:23:15.491Z; AKA_A2=A; gig_canary=true; gig_canary_ver=11036-5-26541090; dtid=1:js/FnfDMK8oXGFdGBLvHj6a0MORHG/Y1s8MsnGgkzOHUZFX+xRPMb5BlxYFhEK+kIpkTwCggfiODcz2YlbWbQUtOP0qVNZmmPwDHSv2MTM7l1Fc=; cw-arjshtsw=p1a864245d3b9452787dfd88a9671c302pwkqrbhkl; akavpau_vpshop=1592468120~id=29ff300510c713e6ed5a307d2bbb707a; ai_sessioncw-=5JXSn|1592467820537.885|1592467820537.885",
#     "dnt": "1",
#     "expires": "Sat, 01 Jan 2000 00:00:00 GMT",
    "pragma": "no-cache",
    "request-id": "|152bd0342157410fba1b6a2e34e5356c.2a93cdb1dc4f49fe",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-requested-with": "OnlineShopping.WebApp",
}
r = requests.get(url, headers=headers)

In [36]:
import json

BODY = json.dumps({
    'sku': '32467',
    'name': 'Green & Blacks Chocolate Block Dark 85% Cocoa',
    'description': 'description',
    'size': {'volumeSize': '90g', 'cupMeasure': '100g', 'cupPrice': 3.3},
    'price': {'originalPrice': 3.33, 'salePrice': 3},
})

BODY


Out[36]:
'{"sku": "32467", "name": "Green & Blacks Chocolate Block Dark 85% Cocoa", "description": "description", "size": {"volumeSize": "90g", "cupMeasure": "100g", "cupPrice": 3.3}, "price": {"originalPrice": 3.33, "salePrice": 3}}'

In [25]:
d["size"]


Out[25]:
{'cupPrice': 10.0,
 'cupMeasure': '1KG',
 'packageType': None,
 'volumeSize': '1kg'}

In [ ]: