{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Leaflet cluster map of talk locations\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: getorg in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (0.3.1)\n", "Requirement already satisfied: geopy in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from getorg) (2.3.0)\n", "Requirement already satisfied: retrying in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from getorg) (1.3.4)\n", "Requirement already satisfied: pygithub in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from getorg) (1.58.1)\n", "Requirement already satisfied: geographiclib<3,>=1.52 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from geopy->getorg) (2.0)\n", "Requirement already satisfied: pyjwt[crypto]>=2.4.0 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pygithub->getorg) (2.6.0)\n", "Requirement already satisfied: requests>=2.14.0 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pygithub->getorg) (2.28.1)\n", "Requirement already satisfied: deprecated in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pygithub->getorg) (1.2.13)\n", "Requirement already satisfied: pynacl>=1.4.0 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pygithub->getorg) (1.5.0)\n", "Requirement already satisfied: six>=1.7.0 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from retrying->getorg) (1.16.0)\n", "Requirement already satisfied: cryptography>=3.4.0 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pyjwt[crypto]>=2.4.0->pygithub->getorg) (38.0.1)\n", "Requirement already satisfied: cffi>=1.4.1 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from pynacl>=1.4.0->pygithub->getorg) (1.15.1)\n", "Requirement already satisfied: charset-normalizer<3,>=2 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (2.1.1)\n", "Requirement already satisfied: idna<4,>=2.5 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (3.4)\n", "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (1.26.11)\n", "Requirement already satisfied: certifi>=2017.4.17 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from requests>=2.14.0->pygithub->getorg) (2022.12.7)\n", "Requirement already satisfied: wrapt<2,>=1.10 in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from deprecated->pygithub->getorg) (1.15.0)\n", "Requirement already satisfied: pycparser in /homes/gws/ylsheng/miniconda3/lib/python3.9/site-packages (from cffi>=1.4.1->pynacl>=1.4.0->pygithub->getorg) (2.21)\n", "Iywidgets and ipyleaflet support disabled. You must be in a Jupyter notebook to use this feature.\n", "Error raised:\n", "No module named 'ipyleaflet'\n", "Check that you have enabled ipyleaflet in Jupyter with:\n", " jupyter nbextension enable --py ipyleaflet\n" ] } ], "source": [ "!pip install getorg --upgrade\n", "import glob\n", "import getorg\n", "from geopy import Nominatim" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "g = glob.glob(\"*.md\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "geocoder = Nominatim()\n", "location_dict = {}\n", "location = \"\"\n", "permalink = \"\"\n", "title = \"\"" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Berkeley CA, USA \n", " Berkeley, Alameda County, California, United States of America\n", "Los Angeles, CA \n", " LA, Los Angeles County, California, United States of America\n", "London, UK \n", " London, Greater London, England, UK\n", "San Francisco, California \n", " SF, California, United States of America\n" ] } ], "source": [ "\n", "for file in g:\n", " with open(file, 'r') as f:\n", " lines = f.read()\n", " if lines.find('location: \"') > 1:\n", " loc_start = lines.find('location: \"') + 11\n", " lines_trim = lines[loc_start:]\n", " loc_end = lines_trim.find('\"')\n", " location = lines_trim[:loc_end]\n", " \n", " \n", " location_dict[location] = geocoder.geocode(location)\n", " print(location, \"\\n\", location_dict[location])\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "'Written map to ../talkmap/'" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "m = getorg.orgmap.create_map_obj()\n", "getorg.orgmap.output_html_cluster_map(location_dict, folder_name=\"../talkmap\", hashed_usernames=False)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "base", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 0 }