Iterate over datasources
This commit is contained in:
parent
8e8b498765
commit
176982b750
@ -20,6 +20,7 @@ use data_source::DataSource;
|
||||
pub struct CGGDataSource;
|
||||
impl DataSource for CGGDataSource {
|
||||
fn get_champs_with_positions_and_patch(
|
||||
&self,
|
||||
client: &reqwest::Client,
|
||||
) -> (IndexMap<String, Vec<String>>, String) {
|
||||
let page = client
|
||||
|
@ -40,6 +40,7 @@ const ITEM_TYPES: &'static [(&str, [&str; 2]); 4] = &[
|
||||
|
||||
pub trait DataSource {
|
||||
fn get_champs_with_positions_and_patch(
|
||||
&self,
|
||||
client: &reqwest::Client,
|
||||
) -> (IndexMap<String, Vec<String>>, String);
|
||||
fn get_champ_data(id: &str, position: &str, client: &reqwest::Client) -> Option<Value>;
|
||||
@ -73,6 +74,7 @@ pub trait DataSource {
|
||||
})
|
||||
}
|
||||
fn write_item_set(
|
||||
&self,
|
||||
id: &str,
|
||||
name: &str,
|
||||
pos: &str,
|
||||
|
42
src/main.rs
42
src/main.rs
@ -85,28 +85,32 @@ fn main() {
|
||||
.unwrap();
|
||||
info!("LoL numbers of champs: {}", champion.data.len());
|
||||
|
||||
let (champs, patch) = CGGDataSource::get_champs_with_positions_and_patch(&client);
|
||||
let data_sources = [CGGDataSource];
|
||||
|
||||
info!("CGG version: {}", patch);
|
||||
info!("CGG numbers of champs: {}", champs.len());
|
||||
for data_source in data_sources.iter() {
|
||||
let (champs, patch) = data_source.get_champs_with_positions_and_patch(&client);
|
||||
|
||||
for (id, positions) in &champs {
|
||||
if champion.data.contains_key(id) {
|
||||
let path = lol_champs_dir.join(&id).join("Recommended");
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
for pos in positions {
|
||||
CGGDataSource::write_item_set(
|
||||
&id,
|
||||
&champion.data.get(id).unwrap().name,
|
||||
&pos,
|
||||
&patch,
|
||||
&path,
|
||||
&client,
|
||||
);
|
||||
thread::sleep(Duration::from_millis(300));
|
||||
info!("CGG version: {}", patch);
|
||||
info!("CGG numbers of champs: {}", champs.len());
|
||||
|
||||
for (id, positions) in &champs {
|
||||
if champion.data.contains_key(id) {
|
||||
let path = lol_champs_dir.join(&id).join("Recommended");
|
||||
fs::create_dir_all(&path).unwrap();
|
||||
for pos in positions {
|
||||
data_source.write_item_set(
|
||||
&id,
|
||||
&champion.data.get(id).unwrap().name,
|
||||
&pos,
|
||||
&patch,
|
||||
&path,
|
||||
&client,
|
||||
);
|
||||
thread::sleep(Duration::from_millis(300));
|
||||
}
|
||||
} else {
|
||||
error!("{} not found in LoL champs", &id);
|
||||
}
|
||||
} else {
|
||||
error!("{} not found in LoL champs", &id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user