Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (56 sloc) 2.02 KB
import sys
from datetime import datetime
from dateutil.parser import parse
import pytz
import csv
#Make a geochart
#from a csv file that has timestamps and addresses with the countries last
#takes one arg (the input file) and outputs the HTML to draw the chart
#To invoke: #python input_file.csv > Country_Chart.html
#read in the csv (when is the first, country is the last)
csv_file = open (sys.argv[1], 'r')
reader = csv.reader(csv_file)
#use a hash to store the countries
for items in reader:
#the time is the first thing
when = items[0]
#figure out the number of years ago the vist was
#at some point should fix this to actually use time zones when we have them
years = int(( - parse(when).replace(tzinfo=pytz.UTC)).days / 365.25)
#the country is the last field in the csv
while country=='':
country = items.pop(-1)
#if we find a country but it is not yet in our hash or in it but a longer number of years ago, write it
if country != 'NONE':
if (not country in countries) or (countries[country]>years):
#write the HTML
print '''
<script type="text/javascript" src=""></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['geochart']});
function drawRegionsMap() {
var data = google.visualization.arrayToDataTable([
['Country', 'Years Since Visit']
for key in countries:
print ',[\''+key+'\', -'+str(countries[key])+']'
print '''
var options = {};
var chart = new google.visualization.GeoChart(document.getElementById('regions_div'));
chart.draw(data, options);
<div id="regions_div" style="width: 900px; height: 500px;"></div>