项目作者: FlorianKempenich

项目描述 :
A simple shopping list cost breakdown calculator
高级语言: Python
项目地址: git://github.com/FlorianKempenich/Shopping-List.git
创建时间: 2018-06-26T10:34:20Z
项目社区:https://github.com/FlorianKempenich/Shopping-List

开源协议:MIT License

下载


Shopping List - Do More, Pay Less

Travis PyPI

shopping_list is a simple tool to calculate the cost breakdown and total of a shopping list containing items in multiple categories.

It allows to create different variation of prices, to compare the influence in the total cost.
See the corresponding section Pro Tip - Price combinations

shopping_list in action

The project was originally created to estimate the total cost of devices in a Home-Automation project and see the influence of different purchase decisions.

Given:

  • A list of prices
  • A shopping list of items per category (per room in the example)

It generates an output breaking down the costs.

  1. > shoppinglist shopping_list.yaml prices.yaml
  2. Total cost breakdown
  3. ---
  4. Living Room: 77.5
  5. Kitchen: 45
  6. Extra: 15
  7. ---
  8. Total: 137.5

With shopping_list.yaml

  1. Living-room:
  2. - InWallSwitch
  3. - InWallSwitch
  4. - PaddleSwitch
  5. - MotionSensor
  6. Kitchen:
  7. - BulbBasic
  8. - BulbAmbiance
  9. Extra:
  10. - Shipping

And prices.yaml

  1. InWallSwitch: 26
  2. PaddleSwitch: 15
  3. MotionSensor: 10.5
  4. BulbBasic: 15
  5. BulbAmbiance: 30
  6. Shipping: 15

Demo versions of these files can be find under demo/

  1. cd demo
  2. shoppinglist shopping_list.yaml prices.yaml

Usage

Installation

  1. pip3 install shoppinglist
  2. # Or
  3. pip3 install --user shoppinglist

Warning: Use python 3!

Usage

  1. Usage: shoppinglist [OPTIONS] SHOPPING_LIST_FILE PRICES_FILE
  2. [PRICE_OVERRIDES_FILES]...
  3. Options:
  4. --with-count Display the count for each item
  5. --without-breakdown Hide the cost breakdown for each category
  6. --help Show this message and exit.

Arguments

SHOPPING_LIST_FILE
  • The shopping list
  • shopping_list.yaml in the previous examples
PRICES_FILE
  • The base prices
  • prices.yaml in the previous examples
[PRICE_OVERRIDES_FILES]
  • Zero or multiple price overrides files
  • A price override has the same format as the PRICES_FILE file
  • PRICE_OVERRIDES_FILES define prices overridings the base prices present in PRICES_FILE
  • Kinda like mixins for the price list
  • In case of multiple overrides, only the last one is taken into account

Format for the files

prices.yaml and price_overrides_*.yaml
  • 1 item per line, with its price
  • See example
shopping_list.yaml
  • 1 block per category
  • Each block contains a list on items
  • Item prices must have been defined in prices.yaml
  • Duplicates allowed, they will be counted twice
  • See example

Pro Tip - Price combinations

Create different combination of prices to see quickly see the influence of your purchase decisions.

To do so, you have 2 options:

  • Define multiple base prices
  • Define a base price and override individual items

Using multiple base prices

For instance amazon.yaml
  1. InWallSwitch: 56 <- More expensive InWallSwitch
  2. PaddleSwitch: 7 <- Cheaper PaddleSwitch
  3. MotionSensor: 10.5
  4. BulbBasic: 15
  5. BulbAmbiance: 30
  6. Shipping: 0 <- Free shipping
Or upgrade_basic_to_ambiance.yaml
  1. InWallSwitch: 26
  2. PaddleSwitch: 15
  3. MotionSensor: 10.5
  4. BulbBasic: 30 <- Bump the price of 'basic' bulb to match
  5. BulbAmbiance: 30 the one of the 'ambiance' variation
  6. and see how it affects the Total!
  7. Shipping: 15
Results
  1. # In 'demo/' folder
  2. > shoppinglist shopping_list.yaml prices.yaml
  3. ...
  4. Total: 137.5
  5. > shoppinglist shopping_list.yaml amazon.yaml
  6. ...
  7. Total: 174.5
  8. > shoppinglist shopping_list.yaml upgrade_basic_to_ambiance.yaml
  9. ...
  10. Total: 152.5

Using prices overrides

With base prices.yaml
  1. InWallSwitch: 26
  2. PaddleSwitch: 15
  3. MotionSensor: 10.5
  4. BulbBasic: 15
  5. BulbAmbiance: 30
  6. Shipping: 15
First override free_shipping.yaml
  1. Shipping: 0 <- Free shipping
Second override tradfri_bulb_instead_of_hue.yaml
  1. BulbBasic: 10 <- Cheaper Bulbs
  2. BulbAmbiance: 20 <- Cheaper Bulbs
Results
  1. # In 'demo/' folder
  2. > shoppinglist shopping_list.yaml prices.yaml
  3. ...
  4. Total: 137.5
  5. > shoppinglist shopping_list.yaml prices.yaml free_shipping.yaml
  6. ...
  7. Total: 122.5
  8. > shoppinglist shopping_list.yaml prices.yaml free_shipping.yaml tradfri_bulb_instead_of_hue.yaml
  9. ...
  10. Total: 107.5

Development

Prerequisites: Pipenv

This project needs pipenv in order to work.

If you haven’t set it up already… please do yourself a favor and read about it. That thing made my life just slightly better… but to the point where I actually notice an increase in my mood while working with python projects.
Kudos to them :)

More info on: Pipenv: Python Development Workflow for Humans

Interested in having that setup automatically for you?
Then check out my ansible role that does just that ;)
==> FlorianKempenich.python-virtualenv

Installation

  1. git clone git@github.com:FlorianKempenich/Shopping-List.git
  2. cd Shopping-List
  3. pipenv install --dev
  4. pipenv shell

Tests

  1. pytest
  2. # Or
  3. ./start_tdd.sh

Author Information

Follow me on Twitter: @ThisIsFlorianK
Find out more about my work: Florian Kempenich - Personal Website