Skip to content

Commit e787ccc

Browse files
committed
add Jupyter notebook for generating talkmap
1 parent 4924963 commit e787ccc

File tree

1 file changed

+70
-40
lines changed

1 file changed

+70
-40
lines changed

Diff for: _talks/talkmap.ipynb

+70-40
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
{
22
"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+
},
312
{
413
"cell_type": "code",
5-
"execution_count": 48,
14+
"execution_count": 1,
615
"metadata": {
7-
"collapsed": true
16+
"collapsed": false
817
},
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+
],
1032
"source": [
33+
"!pip install getorg --upgrade\n",
1134
"import glob\n",
12-
"!pip install getorg\n",
13-
"import getorg"
35+
"import getorg\n",
36+
"from geopy import Nominatim"
1437
]
1538
},
1639
{
1740
"cell_type": "code",
18-
"execution_count": 49,
41+
"execution_count": 2,
1942
"metadata": {
2043
"collapsed": false
2144
},
@@ -26,7 +49,22 @@
2649
},
2750
{
2851
"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,
3068
"metadata": {
3169
"collapsed": false
3270
},
@@ -35,63 +73,55 @@
3573
"name": "stdout",
3674
"output_type": "stream",
3775
"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"
4284
]
4385
}
4486
],
4587
"source": [
88+
"\n",
4689
"for file in g:\n",
4790
" with open(file, 'r') as f:\n",
4891
" 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"
54101
]
55102
},
56103
{
57104
"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,
79106
"metadata": {
80107
"collapsed": false
81108
},
82109
"outputs": [
83110
{
84111
"data": {
85112
"text/plain": [
86-
"10"
113+
"'Written map to ../talkmap/'"
87114
]
88115
},
89-
"execution_count": 42,
116+
"execution_count": 5,
90117
"metadata": {},
91118
"output_type": "execute_result"
92119
}
93120
],
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+
]
95125
},
96126
{
97127
"cell_type": "code",

0 commit comments

Comments
 (0)