|
11 | 11 | "```bash\n",
|
12 | 12 | "sudo apt install jupyter\n",
|
13 | 13 | "sudo apt install python3-pip\n",
|
14 |
| - "pip install getorg --upgrade\n", |
| 14 | + "pip install python-frontmatter getorg --upgrade\n", |
15 | 15 | "```\n",
|
16 | 16 | "\n",
|
17 | 17 | "After which you can run this from the `_talks/` directory, via:\n",
|
|
32 | 32 | "outputs": [],
|
33 | 33 | "source": [
|
34 | 34 | "# Start by installing the dependencies\n",
|
35 |
| - "!pip install getorg --upgrade\n", |
| 35 | + "!pip install python-frontmatter getorg --upgrade\n", |
| 36 | + "import frontmatter\n", |
36 | 37 | "import glob\n",
|
37 | 38 | "import getorg\n",
|
38 | 39 | "from geopy import Nominatim"
|
|
76 | 77 | "source": [
|
77 | 78 | "# Perform geolocation\n",
|
78 | 79 | "for file in g:\n",
|
79 |
| - " with open(file, 'r') as f:\n", |
80 |
| - " lines = f.read()\n", |
81 |
| - " if lines.find('location: \"') > 1:\n", |
82 |
| - " loc_start = lines.find('location: \"') + 11\n", |
83 |
| - " lines_trim = lines[loc_start:]\n", |
84 |
| - " loc_end = lines_trim.find('\"')\n", |
85 |
| - " location = lines_trim[:loc_end]\n", |
86 |
| - " \n", |
87 |
| - " \n", |
88 |
| - " location_dict[location] = geocoder.geocode(location)\n", |
89 |
| - " print(location, \"\\n\", location_dict[location])\n" |
| 80 | + " # Read the file\n", |
| 81 | + " data = frontmatter.load(file)\n", |
| 82 | + " data = data.to_dict()\n", |
| 83 | + "\n", |
| 84 | + " # Press on if the location is not present\n", |
| 85 | + " if 'location' not in data:\n", |
| 86 | + " continue\n", |
| 87 | + "\n", |
| 88 | + " # Prepare the description\n", |
| 89 | + " title = data['title'].strip()\n", |
| 90 | + " venue = data['venue'].strip()\n", |
| 91 | + " location = data['location'].strip()\n", |
| 92 | + " description = f\"{title}\\n{venue}; {location}\"\n", |
| 93 | + " print(description)\n", |
| 94 | + "\n", |
| 95 | + " # Geocode the location and report the status\n", |
| 96 | + " location_dict[description] = geocoder.geocode(location)\n", |
| 97 | + " print(description, location_dict[description])" |
90 | 98 | ]
|
91 | 99 | },
|
92 | 100 | {
|
|
0 commit comments