updated inventory and supps, but also improved the scraper and made a TODO in the CLI because adding inventory with present or future dates doesn't seem to change 'status'

This commit is contained in:
2024-02-04 12:25:56 +01:00
parent fa82e52ed2
commit 482cd220d7
5 changed files with 64 additions and 42 deletions

View File

@@ -448,5 +448,6 @@
"quantityUnit": "caps", "quantityUnit": "caps",
"orderDate": "2024-02-03", "orderDate": "2024-02-03",
"numBottles": 1 "numBottles": 1
} },
{"orderDate":"2014-02-04T23:00:00.000Z","name":"Ashwagandha","quantity":120,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":300,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Crucera-SGS","quantity":60,"quantityUnits":"caps","servingUnit":"caps","numUnitsInServing":1,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"High Absorption CoQ10 with BioPerine","quantity":120,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":100,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Ultimate Omega","quantity":640,"quantityUnits":"mg per Soft Gel","servingUnit":"mg","numUnitsInServing":1280,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Genistein from Sophora Japonica","quantity":60,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":125,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Ginger Root","quantity":100,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":550,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Glucosamine Sulfate","quantity":240,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":750,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Glycine","quantity":250,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":1000,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Liquid Iodine Plus","quantity":59,"quantityUnits":"ml","servingUnit":"ml","numUnitsInServing":0.126,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Super K","quantity":90,"quantityUnits":"caps","servingUnit":"mcg","numUnitsInServing":1500,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Lithium","quantity":100,"quantityUnits":"caps","servingUnit":"mcg","numUnitsInServing":1000,"numBottles":1},{"orderDate":"2014-02-04T23:00:00.000Z","name":"Hyaluronic Acid","quantity":30,"quantityUnits":"caps","servingUnit":"mg","numUnitsInServing":200,"numBottles":1}
] ]

View File

@@ -1,4 +1,4 @@
const getOrderElements = () => Array.from(document.querySelectorAll(".order-details-box")) let getOrderElements = () => Array.from(document.querySelectorAll(".order-details-box"))
function getDateOfOrder(orderEl) { function getDateOfOrder(orderEl) {
return Date.parse( return Date.parse(
@@ -11,7 +11,7 @@ function getDateOfOrder(orderEl) {
); );
} }
const getSupps = orderEl => Array.from(orderEl.children[1].children[0].children); let getSupps = orderEl => Array.from(orderEl.children[1].children[0].children);
SERVINGS_LOOKUP = { SERVINGS_LOOKUP = {
"Liquid D-3 & MK-7": { "Liquid D-3 & MK-7": {
@@ -20,7 +20,7 @@ SERVINGS_LOOKUP = {
}, },
"Crucera-SGS": { "Crucera-SGS": {
numUnitsInServing: 1, numUnitsInServing: 1,
servingUnit: "cap", servingUnit: "caps",
}, },
"Creatine": { "Creatine": {
numUnitsInServing: 5, numUnitsInServing: 5,
@@ -32,7 +32,7 @@ SERVINGS_LOOKUP = {
}, },
"Magnesium Taurate": { "Magnesium Taurate": {
numUnitsInServing: 1, numUnitsInServing: 1,
servingUnit: "cap", servingUnit: "caps",
}, },
"High Absorption Magnesium Glycinate 350": { "High Absorption Magnesium Glycinate 350": {
numUnitsInServing: 350, numUnitsInServing: 350,
@@ -40,15 +40,15 @@ SERVINGS_LOOKUP = {
}, },
"Iron Bisglycinate": { "Iron Bisglycinate": {
numUnitsInServing: 1, numUnitsInServing: 1,
servingUnit: "cap", servingUnit: "caps",
}, },
"Extend-Release Magnesium": { "Extend-Release Magnesium": {
numUnitsInServing: 1, numUnitsInServing: 1,
servingUnit: "cap", servingUnit: "caps",
}, },
"Lutein & Zeaxanthin": { "Lutein & Zeaxanthin": {
numUnitsInServing: 1, numUnitsInServing: 1,
servingUnit: "cap", servingUnit: "caps",
}, },
"Aged Garlic Extract": { "Aged Garlic Extract": {
numUnitsInServing: 600, numUnitsInServing: 600,
@@ -62,9 +62,17 @@ SERVINGS_LOOKUP = {
numUnitsInServing: .25, numUnitsInServing: .25,
servingUnit: "ml", servingUnit: "ml",
}, },
"Glycine": {
numUnitsInServing: 1000,
servingUnit: "mg",
},
"Super K": {
numUnitsInServing: 1500,
servingUnit: "mcg",
},
}; };
const getNumBottles = orderEl => parseInt(orderEl let getNumBottles = orderEl => parseInt(orderEl
.children[1] .children[1]
.children[0] .children[0]
.children[0] .children[0]
@@ -73,7 +81,7 @@ const getNumBottles = orderEl => parseInt(orderEl
.innerText .innerText
.split("Qty: ").slice(-1)[0]); .split("Qty: ").slice(-1)[0]);
const SKIP_THESE = [ let SKIP_THESE = [
"Organic Brown Mustard", "Organic Brown Mustard",
"Sunflower Lecithin", "Sunflower Lecithin",
"Premium Whole Flaxseed", "Premium Whole Flaxseed",
@@ -150,11 +158,16 @@ function makeSuppObj(sup) {
} }
function main(orderCutoffHuman) { function main(orderCutoffHuman, getFirst) {
const orderCutoff = Date.parse(orderCutoffHuman); let orderEls;
const orderEls = getOrderElements() if (!getFirst) {
.filter(el => !el.innerText.includes("Cancelled")) const orderCutoff = Date.parse(orderCutoffHuman);
.filter(el => getDateOfOrder(el) > orderCutoff) orderEls = getOrderElements()
.filter(el => !el.innerText.includes("Cancelled"))
.filter(el => getDateOfOrder(el) > orderCutoff)
} else {
orderEls = [getOrderElements()[0]];
}
let suppEls = []; let suppEls = [];
for (const orderEl of orderEls) { for (const orderEl of orderEls) {
suppEls = suppEls.concat(getSupps(orderEl)); suppEls = suppEls.concat(getSupps(orderEl));
@@ -163,4 +176,4 @@ function main(orderCutoffHuman) {
return suppEls.map(suppEl => makeSuppObj(suppEl)).filter(res => res != null); return suppEls.map(suppEl => makeSuppObj(suppEl)).filter(res => res != null);
} }
console.log(JSON.stringify(main("January 04, 2024"))); console.log(JSON.stringify(main(null, true)));

View File

@@ -82,7 +82,12 @@ def get_num_winter_days_starting(num_days: int, starting: dt.date) -> int:
@app.command() @app.command()
def status(): def status():
"""check if there's enough inventory for the next fill-up; if not, what to order?""" """
check if there's enough inventory for the next fill-up; if not, what to order?
TODO: this doesn't seem to sense pending orders which have been added to inventory.json
maybe because the delivery date is in the present/future?
"""
validate_matches() validate_matches()
config = load_config() config = load_config()
@@ -107,29 +112,32 @@ def status():
qty_needed = sup_inst * num_days_of_inventory_needed qty_needed = sup_inst * num_days_of_inventory_needed
try: try:
inv = inventory[sup_inst.name] inv = inventory[sup_inst.name.lower()]
except KeyError: except KeyError:
print(f"no hit for key '{sup_inst.name}'")
qty_of_inventory = 0 qty_of_inventory = 0
else: needs.append((sup_inst.name, 0, float('inf')))
qty_of_inventory = get_qty_inventory(sup_inst, inv, next_fill_date) continue
qty_of_inventory = get_qty_inventory(sup_inst, inv, next_fill_date)
print(sup_inst.name, int(qty_of_inventory / inv["numUnitsInServing"]))
net_need = int(qty_needed - qty_of_inventory) net_need = int(qty_needed - qty_of_inventory)
if net_need > 0: if net_need > 0:
if qty_of_inventory == 0: num_units_needed = net_need / inv["numUnitsInServing"] # type: ignore
num_bottles_needed = 1 num_bottles_needed = int(math.ceil(num_units_needed / inv["quantity"])) # type: ignore
else:
if sup_inst.name == "magnesium slow release":
print(f"{net_need=}")
print(f"{inv['numUnitsInServing']=}")
print(f"{inv['quantity']=}")
num_units_needed = net_need / inv["numUnitsInServing"] # type: ignore
num_bottles_needed = int(math.ceil(num_units_needed / inv["quantity"])) # type: ignore
needs.append((sup_inst.name, int(num_units_needed), num_bottles_needed)) needs.append((sup_inst.name, int(num_units_needed), num_bottles_needed))
if needs: if needs:
print()
print(f"The next fill-up is on {next_fill_date}, and you won't have enough of:") print(f"The next fill-up is on {next_fill_date}, and you won't have enough of:")
print()
for name, units_needed, num_bottles in needs: for name, units_needed, num_bottles in needs:
bottle = "bottle" if num_bottles == 1 else "bottles" bottle = "bottle" if num_bottles == 1 else "bottles"
print(f"{name} (need {units_needed} units, which is {num_bottles} {bottle})") print(
f"{name} (need {units_needed} units, which is {num_bottles} {bottle})"
)
print()
@app.command() @app.command()

View File

@@ -62,6 +62,5 @@ class Supp:
def quantity_per_day(self) -> float: def quantity_per_day(self) -> float:
return ( return (
sum([self.morning, self.lunch, self.dinner, self.bedtime]) sum([self.morning, self.lunch, self.dinner, self.bedtime])
* 7 * self.days_per_week / 7
/ self.days_per_week
) )

View File

@@ -65,7 +65,7 @@ units = "iu"
winter_only = true winter_only = true
[[supps]] [[supps]]
name = "DHEA" name = "dhea"
morning = 25 morning = 25
[[supps]] [[supps]]
@@ -75,9 +75,8 @@ days_per_week = 3
[[supps]] [[supps]]
name = "EPA/DHA" name = "EPA/DHA"
morning = 2 morning = 1280
dinner = 1 dinner = 640
units = "caps"
[[supps]] [[supps]]
name = "garlic" name = "garlic"
@@ -108,8 +107,8 @@ morning = 300
[[supps]] [[supps]]
name = "iodine" name = "iodine"
morning = 125 morning = 0.126
units = "mcg" units = "ml"
[[supps]] [[supps]]
name = "iron" name = "iron"
@@ -122,7 +121,7 @@ units="mcg"
[[supps]] [[supps]]
name = "k2-mk7" name = "k2-mk7"
morning = 600 morning = 300 # it's actually 600 but I get half of it from the d-3 + mk7 drops + the Super K
units = "mcg" units = "mcg"
[[supps]] [[supps]]
@@ -140,7 +139,8 @@ dinner = 500
[[supps]] [[supps]]
name = "lithium orotate" name = "lithium orotate"
morning = 1 morning = 1000
units = "mcg"
[[supps]] [[supps]]
name = "lycopene" name = "lycopene"
@@ -169,7 +169,7 @@ morning = 1700
units = "mcg" units = "mcg"
[[supps]] [[supps]]
name = "NAC" name = "nac"
morning = 1800 morning = 1800
dinner = 1800 dinner = 1800
@@ -214,4 +214,5 @@ B-50 = "b complex"
"Vitamin K2, MK-4 (Menatetrenone)" = "k2-mk4" "Vitamin K2, MK-4 (Menatetrenone)" = "k2-mk4"
"Super K" = "k1" "Super K" = "k1"
"Ultimate Omega, Lemon" = "epa/dha" "Ultimate Omega, Lemon" = "epa/dha"
"Ultimate Omega" = "epa/dha"
"Lithium" = "lithium orotate"