-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc: update * feat: population data
- Loading branch information
Showing
257 changed files
with
2,367 additions
and
1,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::structs::CountryInfo; | ||
use anyhow::{Context, Result}; | ||
use std::fs; | ||
use std::io::BufReader; | ||
use std::path::Path; | ||
|
||
pub fn read_from_file<F: AsRef<Path>>( | ||
filename: F, | ||
countries_info_list: &mut Vec<(String, CountryInfo)>, | ||
) -> Result<()> { | ||
let file = fs::File::open(&filename).context(format!( | ||
"Could not open population file {:?}", | ||
filename.as_ref() | ||
))?; | ||
let file_reader = BufReader::new(file); | ||
let mut csv_reader = csv::ReaderBuilder::new() | ||
.flexible(true) | ||
.from_reader(file_reader); | ||
for record_result in csv_reader.records() { | ||
let record = record_result?; | ||
if record.len() < 3 { | ||
continue; | ||
} | ||
let alpha3 = &record[1]; | ||
if let Some((_, info)) = countries_info_list | ||
.iter_mut() | ||
.find(|(_, info)| info.alpha3 == alpha3) | ||
{ | ||
info.population = if record.iter().last().unwrap().trim().is_empty() { | ||
&record[record.len() - 2] | ||
} else { | ||
record.iter().last().unwrap() | ||
} | ||
.parse() | ||
.unwrap() | ||
} | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.