library(knitr) library(tidyverse) library(autorecipes) knitr::opts_chunk$set(echo = TRUE, message = FALSE, eval = FALSE)
This .Rmd is designed to be run interactively and should not be knitted.
To run this .Rmd, you need to have a conda environment with autogroceries installed.
conda_env_name <- ""
autogroceries need your Sainsbury's credentials. For security, it's recommended this is saved in a file rather than directly inputted into this script.
The first line must correspond to your UN and the second your PW, no white space.
credentials_path <- ""
Create the paths for outputting the recipebook
and ordered products.
output_dir <- ""
recipebook_path <- file.path(output_dir, "recipebook.rda") if (file.exists(recipebook_path)) { load(recipebook_path) } else { recipebook <- recipebook_example }
Skip this step if you don't want to favourite any recipes.
# reset fav recipes recipes(recipebook)[["fav"]] <- FALSE # change method to "index" and add arg indexes if you wish to fav by index recipebook <- add_favourites(recipebook, method = "manual")
# modify which_days, which_meals, method and fav_only to your liking recipebook <- create_meal_plan( recipebook, which_days = weekdays(), which_meals = c("Lunch", "Dinner"), method = "auto", fav_only = TRUE, set_last_eaten = TRUE ) meal_plan(recipebook)
recipebook <- create_shopping_list( recipebook, filter_method = "minimal" ) shopping_list(recipebook)
save( recipebook, file = file.path(output_dir, "recipebook.rda") )
conda_env_details <- reticulate::conda_list() %>% dplyr::filter(name == conda_env_name) # important to set python path prior to library(reticulate) # https://stackoverflow.com/questions/50145643/unable-to-change-python-path-in-reticulate Sys.setenv(RETICULATE_PYTHON = conda_env_details[["python"]]) library(reticulate) reticulate::py_config()
shopper <- reticulate::import("autogroceries.shopper") sb <- shopper$SainsburysShopper( items = shopping_list(recipebook)[["names"]], n_items = shopping_list(recipebook)[["n"]] ) # load credentials credentials <- readr::read_lines(credentials_path) # setup output path output_path <- file.path(output_dir, paste0(Sys.Date(), "-", "products.csv")) products <- sb$shop( username = credentials[1], password = credentials[2], file = output_path )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.