This commit is contained in:
nyyu 2019-04-21 22:34:08 +02:00
parent d9da160e3f
commit fa34717836
2 changed files with 12 additions and 8 deletions

View file

@ -47,9 +47,9 @@ pub trait DataSource {
fn make_item_set(&self, data: &Value, label: &str) -> Value { fn make_item_set(&self, data: &Value, label: &str) -> Value {
json!({ json!({
"items": data["items"].as_array().unwrap().iter().map(|x| json!({"id": x["id"].as_str(), "count": 1})).collect::<Vec<Value>>(), "items": data["items"].as_array().unwrap().iter().map(|x| json!({"id": x["id"].as_str(), "count": 1})).collect::<Vec<Value>>(),
"type": format!("{} ({:.2}% - {} games)", label, data["winPercent"].as_f64().unwrap() * 100., data["games"].as_u64().unwrap()) "type": format!("{} ({:.2}% - {} games)", label, data["winPercent"].as_f64().unwrap() * 100., data["games"].as_u64().unwrap())
}) })
} }
fn make_item_set_from_list( fn make_item_set_from_list(
@ -75,9 +75,9 @@ pub trait DataSource {
.join("."); .join(".");
} }
json!({ json!({
"items": list.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(), "items": list.iter().map(|x| json!({"id": x.to_string(), "count": 1})).collect::<Vec<Value>>(),
"type": format!("{} {}", label, key_order) "type": format!("{} {}", label, key_order)
}) })
} }
fn write_item_set( fn write_item_set(
&self, &self,
@ -133,7 +133,8 @@ pub trait DataSource {
fs::write( fs::write(
path.join(format!("CGG_{}_{}.json", id, pos)), path.join(format!("CGG_{}_{}.json", id, pos)),
serde_json::to_string_pretty(&item_set).unwrap(), serde_json::to_string_pretty(&item_set).unwrap(),
).unwrap(); )
.unwrap();
} }
None => { None => {
error!("Can't get data for {} at {}", id, pos); error!("Can't get data for {} at {}", id, pos);

View file

@ -60,7 +60,10 @@ fn main() {
info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap()); info!("LoL Champs Folder: {}", lol_champs_dir.to_str().unwrap());
let mut headers = header::HeaderMap::new(); let mut headers = header::HeaderMap::new();
headers.insert(header::USER_AGENT, header::HeaderValue::from_static(USER_AGENT)); headers.insert(
header::USER_AGENT,
header::HeaderValue::from_static(USER_AGENT),
);
let client = reqwest::Client::builder() let client = reqwest::Client::builder()
.default_headers(headers) .default_headers(headers)