Commit c4a9ecba authored by Emmanuel Raviart's avatar Emmanuel Raviart

When the download of a picture fails, try to reuse the existing one.

parent d7ec4b8c
Pipeline #101104 passed with stage
in 2 minutes and 41 seconds
......@@ -97,6 +97,9 @@ fn main() {
deputes.par_iter().for_each(|depute| {
let ident = &depute.etat_civil.ident;
let photo_filename = format!("{}.jpg", depute.uid().get(2..).unwrap());
let photo_file_path = photos_dir.join(&photo_filename);
let photo_temp_filename = format!("{}_temp.jpg", depute.uid().get(2..).unwrap());
let photo_temp_file_path = photos_dir.join(&photo_temp_filename);
let url_photo = format!(
"http://www2.assemblee-nationale.fr/static/tribun/{}/photos/{}",
legislature, photo_filename
......@@ -112,22 +115,30 @@ fn main() {
.current_dir(&photos_dir)
.arg("-q")
.arg("-O")
.arg(&photo_filename)
.arg(&photo_temp_filename)
.arg(&url_photo)
.output()
.expect("Wget failed");
if output.status.success() {
fs::rename(&photo_temp_file_path, &photo_file_path).expect("Renaming of image failed");
return;
}
if retries >= 2 {
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
println!(
"Wget of {} ({} {}) failed => using blank image",
"Wget of {} ({} {}) failed",
url_photo, ident.prenom, ident.nom
);
fs::copy(missing_photo_file_path, photos_dir.join(&photo_filename))
.expect("Copy of blank image failed");
if photo_file_path.exists() {
println!(" => Reusing existing image");
} else {
println!(" => Using blank image");
fs::copy(&missing_photo_file_path, &photo_file_path).expect("Copy of blank image failed");
}
}
if photo_temp_file_path.exists() {
fs::remove_file(&photo_temp_file_path).expect("Temporary image removal failed");
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment