|
36 | 36 | "import frontmatter\n",
|
37 | 37 | "import glob\n",
|
38 | 38 | "import getorg\n",
|
39 |
| - "from geopy import Nominatim" |
| 39 | + "from geopy import Nominatim\n", |
| 40 | + "from geopy.exc import GeocoderTimedOut" |
40 | 41 | ]
|
41 | 42 | },
|
42 | 43 | {
|
|
59 | 60 | },
|
60 | 61 | "outputs": [],
|
61 | 62 | "source": [
|
| 63 | + "# Set the default timeout, in seconds\n", |
| 64 | + "TIMEOUT = 5\n", |
| 65 | + "\n", |
62 | 66 | "# Prepare to geolocate\n",
|
63 | 67 | "geocoder = Nominatim(user_agent=\"academicpages.github.io\")\n",
|
64 | 68 | "location_dict = {}\n",
|
|
99 | 103 | " description = f\"{title}<br />{venue}; {location}\"\n",
|
100 | 104 | "\n",
|
101 | 105 | " # Geocode the location and report the status\n",
|
102 |
| - " location_dict[description] = geocoder.geocode(location)\n", |
103 |
| - " print(description, location_dict[description])" |
| 106 | + " try:\n", |
| 107 | + " location_dict[description] = geocoder.geocode(location, timeout=TIMEOUT)\n", |
| 108 | + " print(description, location_dict[description])\n", |
| 109 | + " except ValueError as ex:\n", |
| 110 | + " print(f\"Error: geocode failed on input {location} with message {ex}\")\n", |
| 111 | + " except GeocoderTimedOut as ex:\n", |
| 112 | + " print(f\"Error: geocode timed out on input {location} with message {ex}\")\n", |
| 113 | + " except Exception as ex:\n", |
| 114 | + " print(f\"An unhandled exception occurred while processing input {location} with message {ex}\")" |
104 | 115 | ]
|
105 | 116 | },
|
106 | 117 | {
|
|
0 commit comments