Skip to content

Commit

Permalink
feat: refactor find missing data script to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Dec 14, 2022
1 parent 6e42be2 commit e0fb457
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 32 deletions.
30 changes: 0 additions & 30 deletions scripts/find-missing-data.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/rust/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn add_headers(rb: RequestBuilder) -> RequestBuilder {
rb.header(FROM, UA_FROM).header(USER_AGENT, UA)
}

fn get_html_from_url(client: Client, url: &str) -> QueryResponse {
pub fn get_html_from_url(client: Client, url: &str) -> QueryResponse {
let mut request = client.get(url);
request = add_headers(request);

Expand Down
49 changes: 49 additions & 0 deletions src/rust/find_missing_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use crate::{
extract::{get_html_from_url, ExtractionPreference},
mariadb,
};
use mariadb_mysql_kbs::{merged_ultraslim::SearchType, search};
use reqwest::blocking::Client;

pub fn run(only: ExtractionPreference) {
println!("Run checking...");
match only {
ExtractionPreference::All => {
check_mariadb();
}
ExtractionPreference::MySQL => {}
ExtractionPreference::MariaDB => {
check_mariadb();
}
};

println!("All done.");
println!("End !");
}

fn check_mariadb() {
check_mariadb_url("https://mariadb.com/kb/en/mysqld-options/");
check_mariadb_url("https://mariadb.com/kb/en/server-system-variables/");
check_mariadb_url("https://mariadb.com/kb/en/server-status-variables/");
}

fn check_mariadb_url(url: &str) {
let client = Client::new();
println!("Checking URL: {}", url);
let response = get_html_from_url(client, url);
let data = mariadb::extract_mariadb_from_text(response);
let loaded_data = search::load_data();
for entry in data {
if entry.name.is_some() {
let entry_name = entry.name.unwrap();
match loaded_data.get_by_name(&entry_name, SearchType::MariaDB) {
Ok(_) => {}
Err(_) => {
if !entry_name.starts_with("--") {
println!("Missing: {:?}", entry_name);
}
}
}
}
}
}
27 changes: 26 additions & 1 deletion src/rust/mariadb-mysql-kbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod cleaner;
pub mod data;
pub mod extract;
pub mod find_missing_data;
pub mod mariadb;
pub mod mysql;

Expand All @@ -20,7 +21,6 @@ struct Cli {

#[derive(Debug, Subcommand)]
enum Commands {
/// Clones repos
#[command(args_conflicts_with_subcommands = true, about = "Extract the data")]
Extract {
#[arg(
Expand All @@ -35,6 +35,20 @@ enum Commands {
)]
dataset: ExtractCommands,
},
#[command(args_conflicts_with_subcommands = true, about = "Find missing data")]
FindMissingData {
#[arg(
long,
require_equals = true,
num_args = 1,
value_name = "source",
default_value_t = ExtractCommands::All,
default_missing_value = "all",
help = "The source to check",
value_enum
)]
source: ExtractCommands,
},
}

#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
Expand All @@ -59,5 +73,16 @@ fn main() {
extract::extract(extract::ExtractionPreference::MariaDB);
}
},
Commands::FindMissingData { source } => match source {
ExtractCommands::All => {
find_missing_data::run(extract::ExtractionPreference::All);
}
ExtractCommands::Mysql => {
find_missing_data::run(extract::ExtractionPreference::MySQL);
}
ExtractCommands::Mariadb => {
find_missing_data::run(extract::ExtractionPreference::MariaDB);
}
},
}
}

0 comments on commit e0fb457

Please sign in to comment.