Skip to content

Commit

Permalink
Optimizing code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ott-cop committed Feb 22, 2024
1 parent 12b7924 commit bd7623d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "getpic"
name = "getpicture"
version = "0.1.0"
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Imxeldownload</h1>
<h1>Getpicture</h1>

> <p>Automation to download images using Excel cell names.</p>
Expand All @@ -14,12 +14,12 @@
<h2>Usage</h2>
<p>Follow the template for using the script:</p>

$ imxceldownload FILE.xlsx SHEET_NAME INITIAL_LINE INITIAL_COLUMN FINAL_LINE FINAL_COLUMN
$ getpicture FILE.xlsx SHEET_NAME INITIAL_LINE INITIAL_COLUMN FINAL_LINE FINAL_COLUMN

<p>When using this command it will create a folder called "downloads" and the downloaded images will be in the same folder.</p><br/>

<h2>Example</h2>

$ imxceldownload products.xlsx ProductsSheet 3 4 20 4
$ getpicture products.xlsx ProductsSheet 3 4 20 4

<p>Using this exact command it will look for the products.xlsx file, the ProductsSheet sheet and then it will download all the images based on the cell names starting from line 3 of column 4 to line 20 of the same column.</p>
17 changes: 5 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use image_search::{download, Arguments};




#[tokio::main]
async fn main() -> Result<(), String> {
let args: Vec<_> = env::args().collect();
Expand All @@ -15,7 +14,7 @@ async fn main() -> Result<(), String> {

if args.len() < 7 {
println!("\nUSAGE:\n\n");
println!("getpic ARQUIVO.xlsx SHEET_NAME LINHA_INICIAL COLUNA_INICIAL LINHA_FINAL COLUNA_FINAL\n");
println!("getpicture ARQUIVO.xlsx SHEET_NAME LINHA_INICIAL COLUNA_INICIAL LINHA_FINAL COLUNA_FINAL\n");
return Err(format!("{icon_error} Digite corretamente os campos."));
}

Expand Down Expand Up @@ -43,14 +42,9 @@ async fn main() -> Result<(), String> {
if range.is_err() { return Err(format!("{icon_error} Não foi possivel encontrar o Sheet ..")); }
let range = range.unwrap();

// Save the initial coordinates and final coordinates
let line = args[3].parse::<u32>().unwrap() - 1;
let col = args[4].parse::<u32>().unwrap() - 1;
let final_line = args[5].parse::<u32>().unwrap() - 1;
let final_col = args[6].parse::<u32>().unwrap() - 1;

// Get the range
let mut all_products: Vec<String> = vec![];
let values = range.range((line, col), (final_line, final_col));
let values = range.range((*i_row - 1, *i_column - 1), (*f_row - 1, *f_column - 1));


// Add names in vec
Expand All @@ -64,11 +58,10 @@ async fn main() -> Result<(), String> {
let value = value.clone();
tokio::spawn(async move {
let image = Arguments::new(value.as_str(), 1).format(image_search::Format::Jpg).directory(Path::new("downloads"));
if let Err(err) = download(image).await {
println!("Error: {}", err)
}
let _ = download(image).await;
})
}).collect();

future::join_all(tasks).await;

println!("{icon_success} Operação concluída com sucesso!");
Expand Down

0 comments on commit bd7623d

Please sign in to comment.