CUADTSHQNPGMWHIJCWXKHNNIY4UJOYZ7XBZA5CJ2VVJJAMSNT4BAC // println!("{}", Fred::tags_series("cpi;united kingdom"));
// save_unemployment_data(&Country::SouthKorea);// for country in countries_with_data().iter() {// println!("\n{}", country.to_string());// save_unemployment_data(&country);// }// println!("{}", title("LFACTTTTKRA657N"));
pub fn data(series_id: &str) -> String {let mut s = String::new();for obs in Fred::series_observations(series_id).observations {s.push_str(&format!("{}, {}\n",obs.date,obs.value,));
pub fn save_data_json(series_id: &str, path: &str) {let data = Fred::series_observations_json(series_id);let save_path = format!("./data/{}", path);fs::create_dir_all(&save_path).unwrap();fs::write(&format!("{}/{}.json",save_path,series_id,),&data,);}/// Save FRED data to disk as csv./// ```/// save_data_csv("LRUNTTTTSIQ156S");/// ```/// To handle breaks the data is saved in a collection of files "LRUNTTTTSIQ156S_a.csv",/// "LRUNTTTTSIQ156S_b.csv" etc.///pub fn save_data_csv(series_id: &str, path: &str) {let alphabet = "abcdefghijklmnopqrstuvwxyz";let mut chars = alphabet.chars();let mut contains_data = false;let save_path = format!("./data/{}", path);let mut data = String::new();for obs in Fred::series_observations(series_id).observations.iter() {let value: Result<f32, _> = obs.value.parse();match value {Ok(val) => {contains_data = true;data.push_str(&obs.to_string());data.push('\n');},Err(val) => {if contains_data {data.pop();fs::create_dir_all(&save_path).unwrap();fs::write(&format!("{}/{}_{}.csv",save_path,series_id,chars.next().expect("Too many breaks"),),&data,);data = String::new();contains_data = false;}},}
/// Save FRED series metadata including title to disk as json./// ```/// save_series_meta("LRUNTTTTSIQ156S");/// ```pub fn save_series_meta(series_id: &str, path: &str) {let data = Fred::series(series_id).to_string();fs::write(&format!("./data/{}/{}.meta",path,series_id,),&data,);}
// TODOpanic!()// deserialize error
vec!("Consumer Price Index: All Items for Korea","Consumer Price Index: All items: Total: Total for the Republic of Korea","Inflation, consumer prices for the Republic of Korea","Consumer Price Index for Republic of Korea","Consumer Price Index: Total All Items for the Republic of Korea",)
fn countries() -> Vec<Country> {
/// Save csv data and meta data to file, for a given `Country`.pub fn save_unemployment_data(country: &Country) {for series in unemployment_series(country).iter() {let path = country.as_path();save_data_csv(&series.id, &path);save_series_meta(&series.id, &path);println!("{}", series.id)}}pub fn update_all_unemployment_data() {for country in countries_with_data().iter() {println!("\n{}", country.to_string());save_unemployment_data(&country);}}/// Return all the countries with good data as a `Vec`.pub fn countries_with_data() -> Vec<Country> {