Guest User

Tracking Apps Script

a guest
Jun 10th, 2015
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function doGet(e) {
  2.   var ids, names, pageTitle, pageHeader;
  3.   if (e.parameters.group=='dev') {
  4.     ids = [2, 3, 9, 1190, 4623, 7598, 11975, 29738, 32917, 37099, 40051];
  5.     names = ['Geoff', 'Jarrod', 'Chris', 'Oded', 'Sklivvz', 'Nick', 'Marc', 'Kevin', 'David', 'Anna', 'balpha'];
  6.     pageTitle = 'Developers';
  7.     pageHeader = 'Stack Exchange Developers';
  8.   }
  9.   else {
  10.     ids = [  620,     1083,  20808, 34933,    42117,  89201,      102159,  140824,    188123,     463168, 1399708, 2415655];
  11.     names = ['Shog9', 'Jon', 'Tim', 'Robert', 'Pops', 'animuson', 'Grace', 'Jaydles', 'bluefeet', 'Abby', 'JNat', 'Ana'];
  12.     pageTitle = 'Community Team';
  13.     pageHeader = 'Stack Exchange Community Growth Team';
  14.   }
  15.   var types = /answered|asked|comment|revised/;
  16.   var res = [], k=0, i, act;
  17.   for (k=0; k<ids.length; k++) {
  18.     var response = UrlFetchApp.fetch("http://stackexchange.com/users/activity/"+ids[k]+"/?page=1&filter=all").getContentText();
  19.     var rows = response.split('<tr>');
  20.     var allrows = [];
  21.     for (i=1; i<rows.length; i++) {
  22.       entries = rows[i].split('<td>');
  23.       if (types.test(entries[3])) {
  24.         act = {};
  25.         act.time = entries[1].split('title="')[1].split('"')[0];
  26.         act.cnt = '<tr><td>'+names[k]+'</td>'+rows[i].split('</tr>')[0].replace(/<a href/g, '<a target="_blank" href')+'</tr>';
  27.         res.push(act);
  28.       }
  29.     }
  30.   }
  31.   res.sort(function(a,b) {return a.time<b.time?1:-1});
  32.   var output = '<h1 style="text-align:center">'+pageHeader+'</h1><table>'+res.map(function(e){return e.cnt}).join('')+'</table>';
  33.   return HtmlService.createHtmlOutput(output).setSandboxMode(HtmlService.SandboxMode.IFRAME).setTitle(pageTitle);
  34. }
RAW Paste Data