Last active
January 4, 2016 07:18
-
-
Save mhawksey/8587272 to your computer and use it in GitHub Desktop.
Hashtagger Map for TAGS http://mashe.hawksey.info/2014/01/making-a-twitter-hashtag-contributor-map-using-tags/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cacheMap(){ | |
var what = "#rhizo14"; | |
var openTag = '<?xml version="1.0" encoding="UTF-8"?> '+ | |
' <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">' + | |
' <Document>' + | |
' <name><![CDATA[Twitter '+what+' Contributor Map]]></name>' + | |
' <description><![CDATA[Map of Twitter accounts that have used the '+what+' hashtag which include location data. Markers are listed by number of tweets in the archive ]]></description>'; | |
var output = [[openTag]]; | |
var db = ScriptDb.getMyDb(); | |
var counter = 0; | |
var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = doc.getSheetByName("CacheMap"); | |
var data = sheet.getRange(2, 4, sheet.getLastRow(), 4).getValues(); | |
for (var r = 0; r < data.length; r++){ | |
if (data[r][0] !="" && counter < 100){ | |
var results = db.query({user_location: data[r][0]}); | |
if (results.hasNext()){ | |
var item = results.next(); | |
if (item.status !== "ZERO_RESULTS") | |
output.push([formatPlacemark(data[r][2], item.location, data[r][1], data[r][3])]); | |
} else { | |
var maps = Maps.newGeocoder(); | |
Logger.log("%s - %s: %s", r, data[r][1], data[r][0]); | |
var response = maps.geocode(data[r][0]); | |
Utilities.sleep(1000); | |
var resp = {status: response.status, user_location: data[r][0]}; | |
if (response.status !== "ZERO_RESULTS"){ | |
var result = response.results[0]; | |
resp.location = {lat: result.geometry.location.lat,lng: result.geometry.location.lng}; | |
output.push([formatPlacemark(data[r][2], result.geometry.location, data[r][1], data[r][3])]); | |
counter++; | |
} | |
db.save(resp); | |
} | |
} | |
} | |
output.push(['</Document></kml>']); | |
doc.getSheetByName("CacheMap").getRange(1, 1, output.length).setValues(output); | |
} | |
function formatPlacemark(handle, loc, desc, imagesrc){ | |
return '<Placemark>' + | |
'<name>'+handle+'</name>' + | |
'<Point><coordinates>'+loc.lng +','+loc.lat+'</coordinates></Point>' + | |
'<description><![CDATA[ ' + | |
'<img alt="'+handle+'" src="'+imagesrc+'" style="float:left; padding: 0 3px 3px" /> ' + | |
desc +'<br/>' + | |
'<a href="https://twitter.com/'+handle+'">View Profile Twitter</a> | <a href="http://hawksey.info/tagsexplorer/?key=tDHgQeSbHR3fcvN81EHnxQQ&sheet=oaw&gqw=lower(C)%20contains%27'+handle.toLowerCase()+'%27%20OR%20lower(B)%3D%27'+handle.toLowerCase()+'%27">View #rhizo14 convo graph</a>' + | |
'<hr style="clear:both"/>' + | |
']]>' + | |
'</description>' + | |
'</Placemark>' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment