|
1 | 1 | {
|
2 | 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 | + }, |
3 | 12 | {
|
4 | 13 | "cell_type": "code",
|
5 |
| - "execution_count": 48, |
| 14 | + "execution_count": 1, |
6 | 15 | "metadata": {
|
7 |
| - "collapsed": true |
| 16 | + "collapsed": false |
8 | 17 | },
|
9 |
| - "outputs": [], |
| 18 | + "outputs": [ |
| 19 | + { |
| 20 | + "name": "stdout", |
| 21 | + "output_type": "stream", |
| 22 | + "text": [ |
| 23 | + "Requirement already up-to-date: getorg in /home/vm/anaconda3/lib/python3.5/site-packages\n", |
| 24 | + "Requirement already up-to-date: geopy in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n", |
| 25 | + "Requirement already up-to-date: retrying in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n", |
| 26 | + "Requirement already up-to-date: pygithub in /home/vm/anaconda3/lib/python3.5/site-packages (from getorg)\n", |
| 27 | + "Requirement already up-to-date: six>=1.7.0 in /home/vm/.local/lib/python3.5/site-packages (from retrying->getorg)\n", |
| 28 | + "IPywidgets and ipyleaflet support enabled.\n" |
| 29 | + ] |
| 30 | + } |
| 31 | + ], |
10 | 32 | "source": [
|
| 33 | + "!pip install getorg --upgrade\n", |
11 | 34 | "import glob\n",
|
12 |
| - "!pip install getorg\n", |
13 |
| - "import getorg" |
| 35 | + "import getorg\n", |
| 36 | + "from geopy import Nominatim" |
14 | 37 | ]
|
15 | 38 | },
|
16 | 39 | {
|
17 | 40 | "cell_type": "code",
|
18 |
| - "execution_count": 49, |
| 41 | + "execution_count": 2, |
19 | 42 | "metadata": {
|
20 | 43 | "collapsed": false
|
21 | 44 | },
|
|
26 | 49 | },
|
27 | 50 | {
|
28 | 51 | "cell_type": "code",
|
29 |
| - "execution_count": 50, |
| 52 | + "execution_count": 3, |
| 53 | + "metadata": { |
| 54 | + "collapsed": true |
| 55 | + }, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "geocoder = Nominatim()\n", |
| 59 | + "location_dict = {}\n", |
| 60 | + "location = \"\"\n", |
| 61 | + "permalink = \"\"\n", |
| 62 | + "title = \"\"" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": 4, |
30 | 68 | "metadata": {
|
31 | 69 | "collapsed": false
|
32 | 70 | },
|
|
35 | 73 | "name": "stdout",
|
36 | 74 | "output_type": "stream",
|
37 | 75 | "text": [
|
38 |
| - "City, Country\n", |
39 |
| - "City, Country\n", |
40 |
| - "City, Country\n", |
41 |
| - "City, Country\n" |
| 76 | + "Berkeley CA, USA \n", |
| 77 | + " Berkeley, Alameda County, California, United States of America\n", |
| 78 | + "Los Angeles, CA \n", |
| 79 | + " LA, Los Angeles County, California, United States of America\n", |
| 80 | + "London, UK \n", |
| 81 | + " London, Greater London, England, UK\n", |
| 82 | + "San Francisco, California \n", |
| 83 | + " SF, California, United States of America\n" |
42 | 84 | ]
|
43 | 85 | }
|
44 | 86 | ],
|
45 | 87 | "source": [
|
| 88 | + "\n", |
46 | 89 | "for file in g:\n",
|
47 | 90 | " with open(file, 'r') as f:\n",
|
48 | 91 | " lines = f.read()\n",
|
49 |
| - " loc_start = lines.find('location: \"') + 11\n", |
50 |
| - " lines_trim = lines[loc_start:]\n", |
51 |
| - " loc_end = lines_trim.find('\"')\n", |
52 |
| - " print(lines_trim[:loc_end])\n", |
53 |
| - " \n" |
| 92 | + " if lines.find('location: \"') > 1:\n", |
| 93 | + " loc_start = lines.find('location: \"') + 11\n", |
| 94 | + " lines_trim = lines[loc_start:]\n", |
| 95 | + " loc_end = lines_trim.find('\"')\n", |
| 96 | + " location = lines_trim[:loc_end]\n", |
| 97 | + " \n", |
| 98 | + " \n", |
| 99 | + " location_dict[location] = geocoder.geocode(location)\n", |
| 100 | + " print(location, \"\\n\", location_dict[location])\n" |
54 | 101 | ]
|
55 | 102 | },
|
56 | 103 | {
|
57 | 104 | "cell_type": "code",
|
58 |
| - "execution_count": 43, |
59 |
| - "metadata": { |
60 |
| - "collapsed": false |
61 |
| - }, |
62 |
| - "outputs": [ |
63 |
| - { |
64 |
| - "data": { |
65 |
| - "text/plain": [ |
66 |
| - "175" |
67 |
| - ] |
68 |
| - }, |
69 |
| - "execution_count": 43, |
70 |
| - "metadata": {}, |
71 |
| - "output_type": "execute_result" |
72 |
| - } |
73 |
| - ], |
74 |
| - "source": [] |
75 |
| - }, |
76 |
| - { |
77 |
| - "cell_type": "code", |
78 |
| - "execution_count": 42, |
| 105 | + "execution_count": 5, |
79 | 106 | "metadata": {
|
80 | 107 | "collapsed": false
|
81 | 108 | },
|
82 | 109 | "outputs": [
|
83 | 110 | {
|
84 | 111 | "data": {
|
85 | 112 | "text/plain": [
|
86 |
| - "10" |
| 113 | + "'Written map to ../talkmap/'" |
87 | 114 | ]
|
88 | 115 | },
|
89 |
| - "execution_count": 42, |
| 116 | + "execution_count": 5, |
90 | 117 | "metadata": {},
|
91 | 118 | "output_type": "execute_result"
|
92 | 119 | }
|
93 | 120 | ],
|
94 |
| - "source": [] |
| 121 | + "source": [ |
| 122 | + "m = getorg.orgmap.create_map_obj()\n", |
| 123 | + "getorg.orgmap.output_html_cluster_map(location_dict, folder_name=\"../talkmap\", hashed_usernames=False)" |
| 124 | + ] |
95 | 125 | },
|
96 | 126 | {
|
97 | 127 | "cell_type": "code",
|
|
0 commit comments