Skip to content

Commit

Permalink
refactor and handle amazon book case
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu999 committed Nov 26, 2024
1 parent 5d5d49c commit 874901d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Track any value on the web and get notified when it changes. Example: ebay, amaz
### CSS selectors ([how?](https://www.glowmetrics.com/blog/how-to-test-css-selectors-using-the-chrome-dev-console/))
| Website | Element | CSS Selector |
|---------|---------|--------------|
| Amazon | Product Price | `.a-offscreen` |
| Amazon | Book Price | `.aok-offscreen` |
| Amazon | Item Price | `.a-offscreen` |
| ebay | Product Price | `div.x-price-primary span.ux-textspans` |
28 changes: 17 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,33 @@ impl Default for ThisApp {
#[derive(PartialEq, Clone, Copy)]
enum SelectorOption {
Custom,
AmazonPrice,
AmazonItemPrice,
AmazonBookPrice,
EbayPrice,
}

impl SelectorOption {
fn as_str(&self) -> &'static str {
match self {
SelectorOption::Custom => "Custom",
SelectorOption::AmazonPrice => "Amazon Price",
SelectorOption::AmazonItemPrice => "Amazon Item Price",
SelectorOption::AmazonBookPrice => "Amazon Book Price",
SelectorOption::EbayPrice => "Ebay Price",
}
}

fn get_options() -> [SelectorOption; 4] {
[SelectorOption::Custom, SelectorOption::AmazonItemPrice, SelectorOption::AmazonBookPrice, SelectorOption::EbayPrice
]
}

fn get_selector(&self) -> &'static str {
match self {
SelectorOption::Custom => "",
SelectorOption::AmazonPrice => ".a-offscreen",
SelectorOption::AmazonItemPrice => ".a-offscreen",
SelectorOption::AmazonBookPrice => ".aok-offscreen",
SelectorOption::EbayPrice => "div.x-price-primary span.ux-textspans",

}
}
}
Expand Down Expand Up @@ -359,14 +368,11 @@ impl ThisApp {
});
ui.horizontal(|ui| {
ui.label("CSS Selector:");
let options = [SelectorOption::Custom, SelectorOption::AmazonPrice, SelectorOption::EbayPrice];
let current_option = if this.runtime_state.new_row_css_selector == ".a-offscreen" {
SelectorOption::AmazonPrice
} else if this.runtime_state.new_row_css_selector == "div.x-price-primary span.ux-textspans" {
SelectorOption::EbayPrice
} else {
SelectorOption::Custom
};
let options = SelectorOption::get_options();
let current_option = options.iter()
.find(|&&opt| opt.get_selector() == this.runtime_state.new_row_css_selector)
.copied()
.unwrap_or(SelectorOption::Custom);

let mut selected_option = current_option;

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async fn get_current_value(url: &str, css_selector: &str) -> Result<String, Box<
value_string.remove(0);
value_string.pop();
}
value_string = value_string.trim().to_string();

Ok(value_string)
}
Expand Down

0 comments on commit 874901d

Please sign in to comment.