add some error handling for image fetcher

main
Brendan Howell 3 years ago
parent dcb226b3a4
commit 2a432aef92

1
.gitignore vendored

@ -0,0 +1 @@
specimen_img_raw/*.jpg

@ -1,5 +1,6 @@
import glob import glob
import time import time
import urllib.error
import urllib.request import urllib.request
import requests import requests
@ -30,7 +31,14 @@ with open("barcode_cleaned.csv") as bcfile:
rdf_url = "https://www.botanicalcollections.be/specimen/" + barcode + "/rdf" rdf_url = "https://www.botanicalcollections.be/specimen/" + barcode + "/rdf"
print("fetching", rdf_url) print("fetching", rdf_url)
try:
img_url = find_image(rdf_url) img_url = find_image(rdf_url)
except urllib.error.HTTPError as er:
print("Error on ", rdf_url, str(er))
continue
if img_url is None:
print("Error. No image for barcode.")
continue
img_ext = str(img_url).rsplit(".", 1)[1] img_ext = str(img_url).rsplit(".", 1)[1]
print("image url:", img_url) print("image url:", img_url)
save_path = "specimen_img_raw/" + barcode + "." + img_ext save_path = "specimen_img_raw/" + barcode + "." + img_ext

Loading…
Cancel
Save