Trump Dump Data & Playing with TAGS


Image from page 60 of “Children’s ballads from history and folklore” (1886) flickr photo by Internet Archive Book Images shared with no copyright restriction (Flickr Commons)

Driven mad by curiousity after this Matthew Baldwin tweet, I built this little thing. It uses the amazing Martin Hawksey’s TAGS for gathering the Tweets in Google Sheets and then displays it with Vue.js (which I’m sort of learning).

It led me to realize that I could extend TAGS without much effort.

My first attempt was to write two custom functions to get favorites and retweets. Turns out that was pretty straight forward given all Martin’s work.

function getRt (input){
  var theTweet = TAGS.get('statuses/show',{id: input});
  var theRt = theTweet.retweet_count;
  return theRt;
}

function getFav (input){
  var theTweet = TAGS.get('statuses/show',{id: input});
  var theFav = theTweet.favorite_count;
  return theFav;  
}

The TAGS element (TAGS.get) links me into Martin’s library and that’s that. So very easy once you know and then you’re just navigating the Twitter API.

Turns out I can do something similar to get the Twitter bio.

function getBio(input){
  var theTweet = TAGS.get('users/show',{id: input});
  var theBio = theTweet.description;
  return theBio; 
}

Initially, I just stuck these in like you’d do normal functions … =getRT(A1) or whatever and it soon ate up all the processing time allowed for my Google Scripts. That caused other things to break. Lesson learned. I then opted to set the value in the script and write that value to the cell.

function seFavFormula () {
  var doc = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = doc.getSheetByName("Archive");
  var range = sheet.getRange("U2:U").getValues();
  var ids = sheet.getRange("A2:A").getValues();
  
  for (i = 0; i < range.length; i++){
    if(range[i]==""){
      var id = ids[i][0];
      sheet.getRange('U'+(i+2)).setValue(getFav(id));
    }    
  }
} 

This little script runs on the spreadsheet change trigger and checks to see if there are any blank cells in the Favorites column (column U) and if so it sets the value with the favorites.

Something similar runs for the retweets.

At some point I’ll probably set it to re-evaluate/re-write the fav/rt data on some sort of expanding time pattern but for now this works.