Browan Object Locator to Google Sheet
@dangermikeb
code:
data:privatelast updated:3 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
convert_out_of_unix_time
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
}
10
const UT = require("unixtimejs");

// get current unixtime:
//var ut = UT.now(); // eg: 1517433903
// unixtime -> UTCString
var utcString = UT.toUTCString(event.body.reported_at/1000); // "Wed, 31 Jan 2018 21:25:03 GMT"
console.dir(utcString);
return utcString
steps.
C_to_F
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
}
12
const { toFahrenheitFmt } = require('celsius');
 
//var Ftemp = toFahrenheitFmt(event.body.decoded.payload.temperature); // 97
var Ftemp = toFahrenheitFmt(steps.trigger.event.body.decoded.payload.temperature); // 97

//console.dir(event.body.decoded.payload)
console.dir(Ftemp)
return Ftemp
//toFahrenheit(36.68, 3); // 98.024
//toFahrenheit('-40.691 degrees C', 5); // -41.24380
steps.
HERE
auth
to use OAuth tokens and API keys in code via theauths object
(auths.here)
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
}
30
const fetch = require('node-fetch');
//const key = process.env.HERE_API_KEY;   // this is how Raymond got the API key, but this didn't work for me
const key = auths.here.apikey          // get the api key

// Console output for debugging
//console.log("key = ");
//console.log(key);
//console.log("auths.here.apikey = ")
//console.log(auths.here.apikey)

// Raymond's code to access Dropbox files
//if(steps.trigger.event['.tag'] !== 'file') $end('wrong type = ' + steps.trigger.event['.tag']);
//let loc = steps.trigger.event.media_info.metadata.location.latitude + ',' + 
//          steps.trigger.event.media_info.metadata.location.longitude;

// Read lat and longitude from Trigger event
let loc = steps.trigger.event.body.decoded.payload.latitude + ',' + 
          steps.trigger.event.body.decoded.payload.longitude;
console.log(loc);
let url = `https://revgeocode.search.hereapi.com/v1/revgeocode?apikey=${key}&at=${loc}`;
//console.log(url);  //debugging - verify there is an API Key in the URL

let resp = await fetch(url);
//return resp
let data = await resp.json();

console.log(data.items[0]);
return data.items[0];
steps.
gps_distance_calc_FANCY
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
}
50
var geo = require('node-geo-distance');
// from https://www.npmjs.com/package/node-geo-distance
// there isn't much documentation, but I think the function is returning a distance in meters
 
//white house
//var coord1 = {
//  latitude: 38.8977330,
 // longitude: -77.0365310
//}
 
// Washington Monument
//var coord2 = {
//  latitude: 38.8894840,
 // longitude: -77.0352790
//}

// Hotspot
var coord1 = {
  latitude: event.body.hotspots[0].lat,
  longitude: event.body.hotspots[0].long
}
 
// BOL
var coord2 = {
  latitude: steps.trigger.event.body.decoded.payload.latitude,
  longitude: steps.trigger.event.body.decoded.payload.longitude
}
   console.log(event.body.hotspots[0].lat);
   console.log(event.body.hotspots[0].long);

geo.vincenty(coord1, coord2, function(dist) {
  console.log(dist);
});
// -> .8 miles from Washinton Monument to White House accorinding to Google, which is about 1287 meters
 
var vincentyDist = geo.vincentySync(coord1, coord2);
console.log(vincentyDist);
console.log(vincentyDist/1609.34);
return vincentyDist/1609.34; // choose to return the vincentyDist, could have returned the haverstineDist instead as both are giving close results 
// convert meters to miles - i.e. 1609.34 meters in a mile
 
 
geo.haversine(coord1, coord2, function(dist) {
  console.log(dist);
});
 
var haversineDist = geo.haversineSync(coord1, coord2);
console.log(haversineDist);
steps.
gps_dist_calc
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
}
22

// from here: https://github.com/cmoncrief/geodist

var geodist = require('geodist')
//console.dir(Array.isArray(event.body.hotspots));
//console.dir(event.body.hotspots.toString());
//console.dir(event.body.hotspots.valueOf());
//console.dir(event.body.hotspots[0].lat);
//console.dir(event.body.hotspots[0].long);
//console.dir(steps.trigger.event.body.decoded.payload.latitude);
//console.dir(steps.trigger.event.body.decoded.payload.longitude);

//var dist = geodist({lat: 41.85, lon: -87.65}, {lat: 33.7489, lon: -84.3881})
// => 587
//var dist = geodist({lat: event.body.hotspots[0].lat, lon: event.body.hotspots[0].long}, {lat: steps.trigger.event.body.decoded.payload.latitude, lon: steps.trigger.event.body.decoded.payload.longitude})
var dist = geodist({lat: event.body.hotspots[0].lat, lon: event.body.hotspots[0].long}, {lat: steps.trigger.event.body.decoded.payload.latitude, lon: steps.trigger.event.body.decoded.payload.longitude}, {exact: true, unit: 'mi'})
// specify to return the result in mlles and the exact result
return dist;
//console.log(dist)           
// => 587
steps.
add_single_row_to_sheet
Add a single row of data to Google Sheets
auth
(auths.google_sheets)
params
Columns

Enter the data to insert into each column. Click + to add columns in structured mode, or turn structured mode off to enter array of column values as an expression — e.g., {{[1,2,3]}}

[0]:
 
array ·params.columns
Spreadsheet ID

The spreadsheet ID can be extracted from its URL. E.g., the spreadsheet ID in the URL docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is abc1234567.

 
1mweDONSnGMtVV1j1-X3NXnkMMnre9IxlTwq8v-rys2E
string ·params.spreadsheetId
Sheet Name

Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1.

 
Sheet1
string ·params.sheetName
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
}
28
const { columns } = params

// validate input
if (!columns || !columns.length) {
  throw new Error("Please enter an array of elements in the `Columns` parameter above")
} else if (!Array.isArray(columns)) {
  throw new Error("Column data is not an array. Please enter an array of elements in the `Columns` parameter above.")
} else if (Array.isArray(columns[0])) {
  throw new Error("Column data is a multi-dimensional array. A one-dimensional is expected. If you're trying to send multiple rows to Google Sheets, search for the action to add multiple rows to Sheets, or try modifying the code for this step.")
}

const config = {
  method: "post",
  url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.sheetName}:append`,
  params: {
    includeValuesInResponse: true,
    valueInputOption: "USER_ENTERED"
  },
  headers: {
    Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
  }, 
  data: {
   values: [columns],
  }
}
return (await require("@pipedreamhq/platform").axios(this, config)).updates