Skip to content

Commit

Permalink
Adds .env to gitignore & clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarcelomb committed Jun 10, 2024
1 parent bc5474c commit 1fe2415
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
}
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.venv
.env
**/env_vars.sh
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ repos:
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-json
- id: check-toml
- id: check-yaml
- id: check-shebang-scripts-are-executable
Expand All @@ -12,6 +11,11 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://gitlab.com/bmares/check-json5
rev: v1.0.0
hooks:
- id: check-json5

- repo: https://github.com/doublify/pre-commit-rust
rev: master
hooks:
Expand Down
6 changes: 2 additions & 4 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use teloxide::prelude::*;
pub async fn send_message(msg: &str) -> Message {
log::info!("Sending message: '{}'", msg);
let bot = Bot::from_env();
let res = bot
.send_message(JMARCELOMB_RECIPIENT.clone(), msg)
bot.send_message(JMARCELOMB_RECIPIENT.clone(), msg)
.await
.unwrap();
res
.unwrap()
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ async fn milk_price_command(bot: Bot, msg: Message) -> HandlerResult {
Some(price) => {
bot.send_message(msg.chat.id, format!("Current milk price is '{}' €", price))
.await?;
return Ok(());
Ok(())
}
None => return Ok(()),
None => Ok(()),
}
}
12 changes: 5 additions & 7 deletions src/milk_price.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use reqwest;
use scraper::{Html, Selector};
use thiserror::Error;
use tokio::time::{sleep, Duration};
Expand Down Expand Up @@ -28,12 +27,12 @@ pub async fn get_price(url: &str) -> Result<Option<f32>, PriceError> {
let selector =
Selector::parse("span.ct-price-formatted").map_err(|_| PriceError::HtmlParseError)?;

for element in document.select(&selector) {
if let Some(element) = document.select(&selector).next() {
let text = element.text().collect::<Vec<_>>().join("");
let text = text.trim();
let price_as_float = text
.trim_start_matches('€')
.replace(",", ".")
.replace(',', ".")
.parse::<f32>()?;
return Ok(Some(price_as_float));
}
Expand Down Expand Up @@ -63,17 +62,16 @@ pub async fn price_periodically_checker_thread(url: &str, interval: u64) {
sleep(Duration::from_secs(interval)).await;
log::info!("Checking milk price again..");
let current_price_res = get_price(url).await;
let current_price: f32;

match current_price_res {
let current_price: f32 = match current_price_res {
Ok(price_option) => {
if price_option.is_none() {
continue;
}
current_price = price_option.unwrap();
price_option.unwrap()
}
Err(_) => continue,
}
};

if current_price != last_price {
let value_increased = current_price > last_price;
Expand Down

0 comments on commit 1fe2415

Please sign in to comment.