Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zeskeertwee committed Dec 20, 2024
1 parent da01495 commit 017323d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

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

14 changes: 6 additions & 8 deletions atletiek-nu-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,22 @@ pub(crate) async fn send_request(url: &str) -> anyhow::Result<String> {
let id = REQUEST_COUNTER.fetch_add(1, Ordering::Relaxed);

if let Some(sender) = REQUEST_SENDER.load().deref() {
sender.send((id, req.try_clone().unwrap())).unwrap();
sender.send((id, req.try_clone().unwrap()))?;
}

let res = client.execute(req).await?;

if let Some(sender) = STATUS_SENDER.load().deref() {
sender.send((id, res.status())).unwrap();
sender.send((id, res.status()))?;
}

let text = res.text().await?;

if std::env::var("ATN_DUMP_REQ").is_ok() {
let n = rand::thread_rng().next_u64();

let mut file = File::create(format!("/tmp/atn_req_{}.html", n)).unwrap();
file.write_all(text.as_bytes()).unwrap();
let mut file = File::create(format!("/tmp/atn_req_{}.html", n))?;
file.write_all(text.as_bytes())?;
info!("Dumped request to /tmp/atn_req_{}.html", n);
}

Expand Down Expand Up @@ -117,8 +117,6 @@ pub async fn get_competition_registrations_web<C: CompetitionID>(
models::registrations_list_web::parse(Html::parse_document(&body))
}

// curl 'https://www.athletics.app/atleet/main/1398565/' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Cookie: atletieknu_Session=av73k220pflv57f599g4r0u5c2; __cmpcc=1; __cmpconsentx66181=CPtS9XAPtS9XAAfC1BENDICgAAAAAAAAAAigAAAS0gHAA4AKcAZ8BHgCVwFYAMEAdiA7YB3IEKQJEASjAloAAA; __cmpcccx66181=aBPtVahoAAAAAAA' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: document' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: none' -H 'Sec-Fetch-User: ?1' > grep.html

pub async fn get_athlete_event_result(participant_id: u32) -> anyhow::Result<AthleteEventResults> {
let url = format!("https://www.athletics.app/atleet/main/{}/", participant_id);
let body = send_request(&url).await?;
Expand Down Expand Up @@ -146,8 +144,8 @@ pub async fn search_competitions_for_time_period(
end: NaiveDate,
q: &str,
) -> anyhow::Result<CompetitionsWebList> {
let start = NaiveDateTime::new(start, NaiveTime::from_hms_opt(0, 0, 0).unwrap()).timestamp();
let end = NaiveDateTime::new(end, NaiveTime::from_hms_opt(0, 0, 0).unwrap()).timestamp();
let start = NaiveDateTime::new(start, NaiveTime::from_hms_opt(0, 0, 0).unwrap()).and_utc().timestamp();
let end = NaiveDateTime::new(end, NaiveTime::from_hms_opt(0, 0, 0).unwrap()).and_utc().timestamp();
let url = format!("https://www.athletics.app/feeder.php?page=search&do=events&country=NL&event_soort[]=in&event_soort[]=out&search={}&startDate={}&endDate={}", urlencoding::encode(q), start, end);
let body = send_request(&url).await?;
models::competitions_list_web::parse(Html::parse_document(&body))
Expand Down
3 changes: 1 addition & 2 deletions atletiek-nu-api/src/models/athlete_event_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ impl AthleteEventResults {
pub fn parse(html: Html) -> anyhow::Result<AthleteEventResults> {
let selector = Selector::parse("#uitslagentabel > tbody").unwrap();
let row_selector = Selector::parse("tr").unwrap();
let th_selector = Selector::parse("tr > th").unwrap();
let row_element_selector = Selector::parse("td").unwrap();
let a_selector = Selector::parse("a").unwrap();
let data_span_selector = Selector::parse("span.sortData").unwrap();
Expand All @@ -101,7 +100,7 @@ pub fn parse(html: Html) -> anyhow::Result<AthleteEventResults> {
.select(&selector)
.next() {
Some(v) => v,
None => anyhow::bail!("No results found! (yet?)")
None => bail!("No results found! (yet?)")
};

if table.html().contains("Athletics Champs") {
Expand Down
3 changes: 1 addition & 2 deletions atletiek-nu-api/src/models/competition_registrations_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chrono::NaiveDate;
use regex::Regex;
use scraper::{ElementRef, Html, Selector};
use scraper::node::Element;
use scraper::{ElementRef, Selector};
use serde::{Deserialize, Serialize};

const REGEX_PARTICIPANT_ID: &'static str = r#"https://www.athletics.app/atleet/main/([\d]{0,})/"#;
Expand Down
1 change: 0 additions & 1 deletion atletiek-nu-api/src/models/registrations_list_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use log::{error, trace, warn};
use regex::Regex;
use scraper::{Html, Selector};
use serde::{Deserialize, Serialize};
use super::registrations_list::{RegistrationsList, RegistrationsListElement};

const REGEX_PARTICIPANT_ID: &'static str = r#"deelnemer_id=([0-9]{0,})"#;
const REGEX_CATEGORY_AND_CLUB: &'static str = r#"([\s\S]{1,}) - ([\s\S]{1,})"#;
Expand Down

0 comments on commit 017323d

Please sign in to comment.