diff --git a/.env b/.env index ca380fd..db4cadc 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -URL=http://vk.gy/database \ No newline at end of file +URL=https://vk.gy/database \ No newline at end of file diff --git a/src/extractor/mod.rs b/src/extractor/mod.rs index 2b7dff6..2cbe263 100644 --- a/src/extractor/mod.rs +++ b/src/extractor/mod.rs @@ -25,7 +25,7 @@ pub struct Informations { pub releases: Vec, } -pub fn extract() { +pub fn extract() -> Informations { let response = reqwest::blocking::get(env::var("URL").unwrap()) .unwrap() .text() @@ -37,36 +37,33 @@ pub fn extract() { let divs = document.select(&div_selector); - let mut categories = Informations::default(); + let mut informations = Informations::default(); for div in divs { if let Some(category) = div.select(&scraper::Selector::parse(CATEGORY_TITLE_SELECTOR).unwrap()).next() { let category_title = category.inner_html(); + let content_div = div.select(&scraper::Selector::parse(NEWS_TITLE_SELECTOR).unwrap()).next().unwrap(); match category_title.as_str() { "artists" => { - let content_div = div.select(&scraper::Selector::parse(NEWS_TITLE_SELECTOR).unwrap()).next().unwrap(); - categories.artists = artists::Artist::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); + informations.artists = artists::Artist::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); }, "labels" => { - let content_div = div.select(&scraper::Selector::parse(NEWS_TITLE_SELECTOR).unwrap()).next().unwrap(); - categories.labels = labels::Label::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); + informations.labels = labels::Label::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); } "musicians" => { - let content_div = div.select(&scraper::Selector::parse(NEWS_TITLE_SELECTOR).unwrap()).next().unwrap(); - categories.musicians = musicians::Musician::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); + informations.musicians = musicians::Musician::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); } "releases" => { - let content_div = div.select(&scraper::Selector::parse(NEWS_TITLE_SELECTOR).unwrap()).next().unwrap(); - categories.releases = releases::Release::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); + informations.releases = releases::Release::extract_all(scraper::Html::parse_fragment(&content_div.inner_html())); } _ => {} } } } - println!("{:#?}", categories); + informations } pub(self) fn trim_whitespace(s: &str) -> String { diff --git a/src/main.rs b/src/main.rs index c2cc8bf..b2a1d5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,5 +3,6 @@ mod extractor; fn main() { dotenvy::dotenv().unwrap(); - extractor::extract(); + let informations = extractor::extract(); + println!("{:#?}", informations); }