diff --git a/Cargo.lock b/Cargo.lock index 18fcaf1..1f4ad2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -194,7 +194,7 @@ checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" [[package]] name = "api" -version = "0.2.3" +version = "0.2.4" dependencies = [ "anyhow", "atletiek_nu_api", @@ -469,7 +469,7 @@ dependencies = [ [[package]] name = "atletiek_nu_api" -version = "0.2.1" +version = "0.2.4" dependencies = [ "anyhow", "arc-swap", diff --git a/atletiek-nu-api/src/lib.rs b/atletiek-nu-api/src/lib.rs index 1e55843..60d7a0f 100644 --- a/atletiek-nu-api/src/lib.rs +++ b/atletiek-nu-api/src/lib.rs @@ -64,13 +64,13 @@ pub(crate) async fn send_request(url: &str) -> anyhow::Result { 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?; @@ -78,8 +78,8 @@ pub(crate) async fn send_request(url: &str) -> anyhow::Result { 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); } @@ -117,8 +117,6 @@ pub async fn get_competition_registrations_web( 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 { let url = format!("https://www.athletics.app/atleet/main/{}/", participant_id); let body = send_request(&url).await?; @@ -146,8 +144,8 @@ pub async fn search_competitions_for_time_period( end: NaiveDate, q: &str, ) -> anyhow::Result { - 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)) diff --git a/atletiek-nu-api/src/models/athlete_event_result.rs b/atletiek-nu-api/src/models/athlete_event_result.rs index ee8c0e4..4e1e511 100644 --- a/atletiek-nu-api/src/models/athlete_event_result.rs +++ b/atletiek-nu-api/src/models/athlete_event_result.rs @@ -80,7 +80,6 @@ impl AthleteEventResults { pub fn parse(html: Html) -> anyhow::Result { 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(); @@ -101,7 +100,7 @@ pub fn parse(html: Html) -> anyhow::Result { .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") { diff --git a/atletiek-nu-api/src/models/competition_registrations_list.rs b/atletiek-nu-api/src/models/competition_registrations_list.rs index 5c5493f..9533a61 100644 --- a/atletiek-nu-api/src/models/competition_registrations_list.rs +++ b/atletiek-nu-api/src/models/competition_registrations_list.rs @@ -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,})/"#; diff --git a/atletiek-nu-api/src/models/registrations_list_web.rs b/atletiek-nu-api/src/models/registrations_list_web.rs index 494f2e6..67aa548 100644 --- a/atletiek-nu-api/src/models/registrations_list_web.rs +++ b/atletiek-nu-api/src/models/registrations_list_web.rs @@ -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,})"#;