mirror of
				https://github.com/lov3b/ecb-rates.git
				synced 2025-11-04 07:10:18 +01:00 
			
		
		
		
	Save before filter
This commit is contained in:
		
							
								
								
									
										22
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -41,13 +41,19 @@ async fn main() -> ExitCode {
 | 
				
			|||||||
    let mut parsed = if cache_ok {
 | 
					    let mut parsed = if cache_ok {
 | 
				
			||||||
        cache.as_ref().unwrap().exchange_rate_results.clone()
 | 
					        cache.as_ref().unwrap().exchange_rate_results.clone()
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        match get_and_parse(cli.resolution.to_ecb_url()).await {
 | 
					        let parsed = match get_and_parse(cli.resolution.to_ecb_url()).await {
 | 
				
			||||||
            Ok(k) => k,
 | 
					            Ok(k) => k,
 | 
				
			||||||
            Err(e) => {
 | 
					            Err(e) => {
 | 
				
			||||||
                eprintln!("Failed to get/parse data from ECB: {}", e);
 | 
					                eprintln!("Failed to get/parse data from ECB: {}", e);
 | 
				
			||||||
                return ExitCode::FAILURE;
 | 
					                return ExitCode::FAILURE;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        if !cache_ok {
 | 
				
			||||||
 | 
					            if let Err(e) = Cache::new(parsed.clone()).save() {
 | 
				
			||||||
 | 
					                eprintln!("Failed to save to cache with: {:?}", e);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        parsed
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if !cli.currencies.is_empty() {
 | 
					    if !cli.currencies.is_empty() {
 | 
				
			||||||
@@ -68,11 +74,12 @@ async fn main() -> ExitCode {
 | 
				
			|||||||
                .collect::<Vec<_>>();
 | 
					                .collect::<Vec<_>>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if !cli.display_time {
 | 
					            if !cli.display_time {
 | 
				
			||||||
                for json_value in json_values.iter_mut() {
 | 
					                json_values
 | 
				
			||||||
                    if let Some(map) = json_value.as_object_mut() {
 | 
					                    .iter_mut()
 | 
				
			||||||
 | 
					                    .filter_map(|json_value| json_value.as_object_mut())
 | 
				
			||||||
 | 
					                    .for_each(|map| {
 | 
				
			||||||
                        map.remove_entry("time");
 | 
					                        map.remove_entry("time");
 | 
				
			||||||
                    }
 | 
					                    });
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if cli.compact {
 | 
					            if cli.compact {
 | 
				
			||||||
@@ -94,10 +101,5 @@ async fn main() -> ExitCode {
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    println!("{}", &output);
 | 
					    println!("{}", &output);
 | 
				
			||||||
    if !cache_ok {
 | 
					 | 
				
			||||||
        if let Err(e) = Cache::new(parsed).save() {
 | 
					 | 
				
			||||||
            eprintln!("Failed to save to cache with: {:?}", e);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    ExitCode::SUCCESS
 | 
					    ExitCode::SUCCESS
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user