Guest User

woolie_recipes.py

a guest
Jul 15th, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #!/usr/bin/python
  2. import requests
  3. from pprint import pprint
  4.  
  5. def cost(sku, weightInGrams):
  6.    url = 'https://www2.woolworthsonline.com.au/apis/ui/Search/products'
  7.    cookies = {'w-lrkswrdjp': 'dm-Pickup,f-2706,s-16027'} # Acacia Ridge
  8.    r = requests.get(url, params = {'SearchTerm': sku}, cookies = cookies)
  9.    product = r.json()
  10.    product = product['Products'][0]
  11.    name = product['Name']
  12.    product = product['Products'][0]
  13.    # if missing more than than 10%
  14.    quantity = int(weightInGrams) / int(product['UnitWeightInGrams'])
  15.    if ((int(weightInGrams) % int(product['UnitWeightInGrams'])) /
  16.       float(weightInGrams) > 0.1):
  17.       quantity += 1
  18.    print("%d\t%s\t%dg\t%s" % (quantity, product['Price'], product['UnitWeightInGrams'], name))
  19.    return quantity * product['Price']
  20.  
  21. with open('recipes.tsv','r') as tsv:
  22.    tsv.readline()
  23.    sum = 0
  24.    print("Qty\tPrice\tEach\tName")
  25.    for line in tsv:
  26.       line = line.strip().split('\t')
  27.       sum += cost(line[2], line[3])
Advertisement
Add Comment
Please, Sign In to add comment