Skip to content

Instantly share code, notes, and snippets.

@moleland
moleland / addtimestamp.js
Last active January 16, 2016 04:41
Use javascript to add a time stamp to Kimono API
function transform (data) {
function add_date(item) {
item.date = new Date();
return item;
}
for (var collection in data.results) {
data.results[collection] = data.results[collection].map(add_date);
}
function copyandpaste() {
// Define your variables
var ss = SpreadsheetApp.openById("--GoogleSheetsID--"); // Obtain the ID of your spreadsheet from https://docs.google.com/spreadsheets/d/--GoogleSheetsID--
var OrigSheet = ss.getSheetByName("Sheet1"); // getSheetByName allows you to select the sheet by sheet name. Get the Origin sheet to be copied
var source = OrigSheet.getRange ("A3:F13"); // get the range of cells to be copied
var destSheet = ss.getSheetByName("Summary"); // get the Destination sheet to be pasted
var destRange = destSheet.getRange(destSheet.getLastRow()+1,1); // I want to paste the data in the next empty row, so i use getLastRow()+1
source.copyTo (destRange, {contentsOnly: true});
function retrieveKimonoinGAS() {
//Retrieve data from the below Kimono API URL. &Kimmodify=1 only if you have modified your API through Modify Results function
var url = 'https://www.kimonolabs.com/api/csv/--apiID--?&apikey=--apikey--&kimmodify=1';
var options = {
'method': 'GET', // Method refers to 'Get' or 'Post'. Kimono API supports GET method.
'contentType': 'application/json', // refers to type of data being pulled from Kimono API, in this case is JSON
'muteHttpExceptions' : true
};
@moleland
moleland / splitdate2.gs
Created February 13, 2016 06:49
Split date range into multiple rows in Google Sheets using Google App Scripts
function splitdate2() {
var ss = SpreadsheetApp.openById("--Your Spreadsheet ID--");
var sd = ss.getSheetByName("--Spreadsheet name--");
//find the last row of col. E, which is the no. of days formula
var Evals = sd.getRange("E1:E").getValues();
var Elast = Evals.filter(String).length;
/*find the last row of col. A, which is your data. In case you paste more data appended to Column A,