Skip to content

Commit

Permalink
add Jupyter notebook for generating talkmap
Browse files Browse the repository at this point in the history
  • Loading branch information
staeiou committed Sep 19, 2016
1 parent 4924963 commit e787ccc
Showing 1 changed file with 70 additions and 40 deletions.
110 changes: 70 additions & 40 deletions _talks/talkmap.ipynb
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
{
"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": 48,
"execution_count": 1,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already up-to-date: getorg in /home/vm/anaconda3/lib/python3.5/site-packages\n",
"Requirement already up-to-date: geopy in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n",
"Requirement already up-to-date: retrying in /home/vm/.local/lib/python3.5/site-packages (from getorg)\n",
"Requirement already up-to-date: pygithub in /home/vm/anaconda3/lib/python3.5/site-packages (from getorg)\n",
"Requirement already up-to-date: six>=1.7.0 in /home/vm/.local/lib/python3.5/site-packages (from retrying->getorg)\n",
"IPywidgets and ipyleaflet support enabled.\n"
]
}
],
"source": [
"!pip install getorg --upgrade\n",
"import glob\n",
"!pip install getorg\n",
"import getorg"
"import getorg\n",
"from geopy import Nominatim"
]
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -26,7 +49,22 @@
},
{
"cell_type": "code",
"execution_count": 50,
"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
},
Expand All @@ -35,63 +73,55 @@
"name": "stdout",
"output_type": "stream",
"text": [
"City, Country\n",
"City, Country\n",
"City, Country\n",
"City, Country\n"
"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",
" loc_start = lines.find('location: \"') + 11\n",
" lines_trim = lines[loc_start:]\n",
" loc_end = lines_trim.find('\"')\n",
" print(lines_trim[:loc_end])\n",
" \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": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"175"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 42,
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10"
"'Written map to ../talkmap/'"
]
},
"execution_count": 42,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
"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",
Expand Down

0 comments on commit e787ccc

Please sign in to comment.