|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Leaflet cluster map of talk locations\n", |
| 8 | + "\n", |
| 9 | + "Run this from the _talks/ directory, which contains .md files of all your talks. This scrapes the location YAML field from each .md file, geolocates it with geopy/Nominatim, and uses the getorg library to output data, HTML, and Javascript for a standalone cluster map." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "code", |
| 14 | + "execution_count": 1, |
| 15 | + "metadata": { |
| 16 | + "collapsed": false, |
| 17 | + "execution": { |
| 18 | + "iopub.execute_input": "2025-02-22T01:09:40.748788Z", |
| 19 | + "iopub.status.busy": "2025-02-22T01:09:40.748590Z", |
| 20 | + "iopub.status.idle": "2025-02-22T01:09:41.820985Z", |
| 21 | + "shell.execute_reply": "2025-02-22T01:09:41.820264Z" |
| 22 | + } |
| 23 | + }, |
| 24 | + "outputs": [ |
| 25 | + { |
| 26 | + "name": "stdout", |
| 27 | + "output_type": "stream", |
| 28 | + "text": [ |
| 29 | + "Requirement already satisfied: getorg in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (0.3.1)\r\n" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "name": "stdout", |
| 34 | + "output_type": "stream", |
| 35 | + "text": [ |
| 36 | + "Requirement already satisfied: geopy in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from getorg) (2.4.1)\r\n", |
| 37 | + "Requirement already satisfied: pygithub in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from getorg) (2.6.1)\r\n", |
| 38 | + "Requirement already satisfied: retrying in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from getorg) (1.3.4)\r\n", |
| 39 | + "Requirement already satisfied: geographiclib<3,>=1.52 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from geopy->getorg) (2.0)\r\n", |
| 40 | + "Requirement already satisfied: pynacl>=1.4.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pygithub->getorg) (1.5.0)\r\n", |
| 41 | + "Requirement already satisfied: requests>=2.14.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pygithub->getorg) (2.32.3)\r\n", |
| 42 | + "Requirement already satisfied: pyjwt>=2.4.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pyjwt[crypto]>=2.4.0->pygithub->getorg) (2.10.1)\r\n", |
| 43 | + "Requirement already satisfied: typing-extensions>=4.0.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pygithub->getorg) (4.12.2)\r\n", |
| 44 | + "Requirement already satisfied: urllib3>=1.26.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pygithub->getorg) (2.3.0)\r\n", |
| 45 | + "Requirement already satisfied: Deprecated in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pygithub->getorg) (1.2.18)\r\n", |
| 46 | + "Requirement already satisfied: six>=1.7.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from retrying->getorg) (1.17.0)\r\n", |
| 47 | + "Requirement already satisfied: cryptography>=3.4.0 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pyjwt[crypto]>=2.4.0->pygithub->getorg) (44.0.1)\r\n", |
| 48 | + "Requirement already satisfied: cffi>=1.4.1 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from pynacl>=1.4.0->pygithub->getorg) (1.17.1)\r\n", |
| 49 | + "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (3.4.1)\r\n", |
| 50 | + "Requirement already satisfied: idna<4,>=2.5 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (3.10)\r\n", |
| 51 | + "Requirement already satisfied: certifi>=2017.4.17 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (2025.1.31)\r\n", |
| 52 | + "Requirement already satisfied: wrapt<2,>=1.10 in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from Deprecated->pygithub->getorg) (1.17.2)\r\n", |
| 53 | + "Requirement already satisfied: pycparser in /opt/hostedtoolcache/Python/3.9.21/x64/lib/python3.9/site-packages (from cffi>=1.4.1->pynacl>=1.4.0->pygithub->getorg) (2.22)\r\n" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "name": "stdout", |
| 58 | + "output_type": "stream", |
| 59 | + "text": [ |
| 60 | + "Iywidgets and ipyleaflet support disabled. You must be in a Jupyter notebook to use this feature.\n", |
| 61 | + "Error raised:\n", |
| 62 | + "No module named 'ipyleaflet'\n", |
| 63 | + "Check that you have enabled ipyleaflet in Jupyter with:\n", |
| 64 | + " jupyter nbextension enable --py ipyleaflet\n" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "source": [ |
| 69 | + "!pip install getorg --upgrade\n", |
| 70 | + "import glob\n", |
| 71 | + "import getorg\n", |
| 72 | + "from geopy import Nominatim" |
| 73 | + ] |
| 74 | + }, |
| 75 | + { |
| 76 | + "cell_type": "code", |
| 77 | + "execution_count": 2, |
| 78 | + "metadata": { |
| 79 | + "collapsed": false, |
| 80 | + "execution": { |
| 81 | + "iopub.execute_input": "2025-02-22T01:09:41.823539Z", |
| 82 | + "iopub.status.busy": "2025-02-22T01:09:41.823058Z", |
| 83 | + "iopub.status.idle": "2025-02-22T01:09:41.826460Z", |
| 84 | + "shell.execute_reply": "2025-02-22T01:09:41.825940Z" |
| 85 | + } |
| 86 | + }, |
| 87 | + "outputs": [], |
| 88 | + "source": [ |
| 89 | + "g = glob.glob(\"*.md\")" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": 3, |
| 95 | + "metadata": { |
| 96 | + "collapsed": true, |
| 97 | + "execution": { |
| 98 | + "iopub.execute_input": "2025-02-22T01:09:41.828648Z", |
| 99 | + "iopub.status.busy": "2025-02-22T01:09:41.828276Z", |
| 100 | + "iopub.status.idle": "2025-02-22T01:09:41.853054Z", |
| 101 | + "shell.execute_reply": "2025-02-22T01:09:41.852554Z" |
| 102 | + } |
| 103 | + }, |
| 104 | + "outputs": [], |
| 105 | + "source": [ |
| 106 | + "geocoder = Nominatim(user_agent=\"academicpages.github.io\")\n", |
| 107 | + "location_dict = {}\n", |
| 108 | + "location = \"\"\n", |
| 109 | + "permalink = \"\"\n", |
| 110 | + "title = \"\"" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": 4, |
| 116 | + "metadata": { |
| 117 | + "collapsed": false, |
| 118 | + "execution": { |
| 119 | + "iopub.execute_input": "2025-02-22T01:09:41.855227Z", |
| 120 | + "iopub.status.busy": "2025-02-22T01:09:41.854845Z", |
| 121 | + "iopub.status.idle": "2025-02-22T01:09:44.188915Z", |
| 122 | + "shell.execute_reply": "2025-02-22T01:09:44.188226Z" |
| 123 | + } |
| 124 | + }, |
| 125 | + "outputs": [ |
| 126 | + { |
| 127 | + "name": "stdout", |
| 128 | + "output_type": "stream", |
| 129 | + "text": [ |
| 130 | + " \n", |
| 131 | + " None\n" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "name": "stdout", |
| 136 | + "output_type": "stream", |
| 137 | + "text": [ |
| 138 | + " \n", |
| 139 | + " None\n" |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + "source": [ |
| 144 | + "\n", |
| 145 | + "for file in g:\n", |
| 146 | + " with open(file, 'r') as f:\n", |
| 147 | + " lines = f.read()\n", |
| 148 | + " if lines.find('location: \"') > 1:\n", |
| 149 | + " loc_start = lines.find('location: \"') + 11\n", |
| 150 | + " lines_trim = lines[loc_start:]\n", |
| 151 | + " loc_end = lines_trim.find('\"')\n", |
| 152 | + " location = lines_trim[:loc_end]\n", |
| 153 | + " \n", |
| 154 | + " \n", |
| 155 | + " location_dict[location] = geocoder.geocode(location)\n", |
| 156 | + " print(location, \"\\n\", location_dict[location])\n" |
| 157 | + ] |
| 158 | + }, |
| 159 | + { |
| 160 | + "cell_type": "code", |
| 161 | + "execution_count": 5, |
| 162 | + "metadata": { |
| 163 | + "collapsed": false, |
| 164 | + "execution": { |
| 165 | + "iopub.execute_input": "2025-02-22T01:09:44.191211Z", |
| 166 | + "iopub.status.busy": "2025-02-22T01:09:44.190804Z", |
| 167 | + "iopub.status.idle": "2025-02-22T01:09:44.198598Z", |
| 168 | + "shell.execute_reply": "2025-02-22T01:09:44.197939Z" |
| 169 | + } |
| 170 | + }, |
| 171 | + "outputs": [ |
| 172 | + { |
| 173 | + "data": { |
| 174 | + "text/plain": [ |
| 175 | + "'Written map to ../talkmap/'" |
| 176 | + ] |
| 177 | + }, |
| 178 | + "execution_count": 5, |
| 179 | + "metadata": {}, |
| 180 | + "output_type": "execute_result" |
| 181 | + } |
| 182 | + ], |
| 183 | + "source": [ |
| 184 | + "m = getorg.orgmap.create_map_obj()\n", |
| 185 | + "getorg.orgmap.output_html_cluster_map(location_dict, folder_name=\"../talkmap\", hashed_usernames=False)" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "cell_type": "code", |
| 190 | + "execution_count": null, |
| 191 | + "metadata": { |
| 192 | + "collapsed": true |
| 193 | + }, |
| 194 | + "outputs": [], |
| 195 | + "source": [] |
| 196 | + } |
| 197 | + ], |
| 198 | + "metadata": { |
| 199 | + "anaconda-cloud": {}, |
| 200 | + "kernelspec": { |
| 201 | + "display_name": "Python 3", |
| 202 | + "language": "python", |
| 203 | + "name": "python3" |
| 204 | + }, |
| 205 | + "language_info": { |
| 206 | + "codemirror_mode": { |
| 207 | + "name": "ipython", |
| 208 | + "version": 3 |
| 209 | + }, |
| 210 | + "file_extension": ".py", |
| 211 | + "mimetype": "text/x-python", |
| 212 | + "name": "python", |
| 213 | + "nbconvert_exporter": "python", |
| 214 | + "pygments_lexer": "ipython3", |
| 215 | + "version": "3.9.21" |
| 216 | + } |
| 217 | + }, |
| 218 | + "nbformat": 4, |
| 219 | + "nbformat_minor": 0 |
| 220 | +} |
0 commit comments