Leaflet cluster map of talk locations

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.


In [2]:
!pip install getorg --upgrade
import glob
import getorg
from geopy import Nominatim


Requirement already up-to-date: getorg in /usr/local/lib/python2.7/dist-packages
Requirement already up-to-date: retrying in /usr/local/lib/python2.7/dist-packages (from getorg)
Requirement already up-to-date: geopy in /usr/local/lib/python2.7/dist-packages (from getorg)
Requirement already up-to-date: pygithub in /usr/local/lib/python2.7/dist-packages (from getorg)
Collecting six>=1.7.0 (from retrying->getorg)
  Using cached six-1.11.0-py2.py3-none-any.whl
Collecting pyjwt (from pygithub->getorg)
  Using cached PyJWT-1.5.3-py2.py3-none-any.whl
Installing collected packages: six, pyjwt
  Found existing installation: six 1.10.0
    Uninstalling six-1.10.0:
      Successfully uninstalled six-1.10.0
  Rolling back uninstall of six
Exception:
Traceback (most recent call last):
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/leonardo/.local/lib/python2.7/site-packages/pip/wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/six.py'

In [2]:
g = glob.glob("*.md")

In [3]:
geocoder = Nominatim()
location_dict = {}
location = ""
permalink = ""
title = ""

In [4]:
for file in g:
    with open(file, 'r') as f:
        lines = f.read()
        if lines.find('location: "') > 1:
            loc_start = lines.find('location: "') + 11
            lines_trim = lines[loc_start:]
            loc_end = lines_trim.find('"')
            location = lines_trim[:loc_end]
                            
           
        location_dict[location] = geocoder.geocode(location)
        print(location, "\n", location_dict[location])


Berkeley CA, USA 
 Berkeley, Alameda County, California, United States of America
Los Angeles, CA 
 LA, Los Angeles County, California, United States of America
London, UK 
 London, Greater London, England, UK
San Francisco, California 
 SF, California, United States of America

In [5]:
m = getorg.orgmap.create_map_obj()
getorg.orgmap.output_html_cluster_map(location_dict, folder_name="../talkmap", hashed_usernames=False)


Out[5]:
'Written map to ../talkmap/'

In [ ]: