diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3dd9c90..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -games.csv -out.csv -result diff --git a/README.md b/README.md index 202f619..72837ab 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,29 @@ This program serves to take a list of boardgames as a csv and return a csv with ### Run the sample -`cat sample_in.csv | nix run` +`cp sample_in.csv in.csv` +`nix run` the output `out.csv` should match the provided `sample_out.csv` +## Quick Windows user guide + +- Make a new folder +- Put `rust_elaborator.exe` into that folder +- Copy your `in.csv`, a list of game names as specified in `Usage`, or `out.csv`, an output from when this program ran previously, into the new folder +- Double-click `rust_elaborator.exe` to run it +- Check that `out.csv` is satisfactory + ## Usage -The program reads a csv from stdin and outputs it to `out.csv`. The following command reads the contents of `in.csv` into the program and runs it. +# WARNING: files may be overwritten -`cat in.csv | rust_elaborator` +The files `in.csv`, `out.csv`, `test.csv`, `copy.csv`, and possibly others may be overwritten and data loss may occur. Run this program in an empty directory with a copy of `in.csv` or `out.csv` and nothing else present for safety. + +The program reads a file `in.csv` or `out.csv` and outpus it to `out.csv`. The following command reads the contents of `in.csv` into the program and runs it. +note that on windows, `rust_elaborator` instead looks like `rust_elaborator.exe` + +`rust_elaborator` `in.csv` must be formatted as follows... @@ -46,8 +60,4 @@ where `title` can be anything. Capitalization does not matter. Additional columns will not be present in `out.csv`. -If you have an existing `out.csv`, you can add new rows and avoid recalling the rows that are already filled in with the flag `--mode expand`. - -`cat out.csv | nix run . -- --mode expand` - -This will only check rows that have a) a blank second column or b) NOT_FOUND in the second column. +If `out.csv` is present, the program will take it as input and elaborate on it. This will fill in rows that have a) a blank second column or b) NOT_FOUND in the second column, if possible. diff --git a/rust_elaborator.exe b/rust_elaborator.exe deleted file mode 100644 index e103bb8..0000000 Binary files a/rust_elaborator.exe and /dev/null differ diff --git a/src/lib.rs b/src/lib.rs index 855b30c..f881f0a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Args { - #[arg(short, long, default_value_t = ("elaborate".to_string()))] + #[arg(short, long, default_value_t = ("infer".to_string()))] pub mode: String, } diff --git a/src/main.rs b/src/main.rs index 027a218..6026b27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use clap::Parser; use reqwest::header::USER_AGENT; use rust_elaborator::*; use std::io; -use std::io::prelude::*; +use std::mem::drop; #[tokio::main] async fn main() -> Result<(), reqwest::Error> { @@ -11,6 +11,13 @@ async fn main() -> Result<(), reqwest::Error> { match args.mode.as_str() { "elaborate" => make_out_from_in().await, "expand" => make_out_from_out().await, + "infer" => { + if std::fs::exists("out.csv").unwrap() { + make_out_from_out().await + } else { + make_out_from_in().await + } + } _ => panic!(), }; Ok(()) @@ -137,11 +144,13 @@ fn find_best_boardgame( } async fn make_out_from_in() -> Result<(), Box> { + println!("making out.csv from in.csv"); use std::fs::File; use std::io::prelude::*; - let mut out = File::create("out.csv").unwrap(); + let mut out = File::create_new("out.csv").unwrap(); + let mut inn = File::open("in.csv").unwrap(); let mut writer = csv::Writer::from_writer(out); - let mut reader = csv::Reader::from_reader(io::stdin()); + let mut reader = csv::Reader::from_reader(inn); writer .write_record(&[ "title", @@ -217,10 +226,13 @@ async fn make_out_from_in() -> Result<(), Box> { } async fn make_out_from_out() -> Result<(), Box> { + println!("making out.csv from out.csv"); use std::fs::File; + std::fs::copy("out.csv", "copy.csv").unwrap(); + let mut copy = File::open("copy.csv").unwrap(); + let mut reader = csv::Reader::from_reader(copy); let mut out = File::create("out.csv").unwrap(); let mut writer = csv::Writer::from_writer(out); - let mut reader = csv::Reader::from_reader(io::stdin()); writer .write_record(&[ "title", @@ -286,7 +298,7 @@ async fn make_out_from_out() -> Result<(), Box> { maxplaytime.as_str(), age.as_str(), ]) - .unwrap() + .unwrap(); } None => writer .write_record(&[title, "NOT_FOUND", "", "", "", "", "", ""]) @@ -299,5 +311,6 @@ async fn make_out_from_out() -> Result<(), Box> { ]); }; } + std::fs::remove_file("copy.csv"); Ok(()) }