npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@danse4mobility/google-sheets-uploader

v0.1.1

Published

Uploads a CSV/TSV file from Amazon S3 storage to a Google Sheets.

Downloads

6

Readme

google-sheets-uploader

An unofficial client intended to download AWS S3 object conatining CSV/TSV file and subsequently insert its conent to specified Google Sheets spreadsheet.

Table of contents

Getting Started

  1. Install module

    npm install @danse4mobility/google-sheets-uploader
  2. Create a project in Google Developer Console, for example: "Google Sheets App"

  3. Enable the Google Sheets API

  4. Create credentials for the Google Sheets API and save the file credentials.json to your working directory

  5. Share the Sheets document to service email address using the Share button

  6. Pick up the Sheets document id from URL or Share dialog. Example:

    # Sheets document browser URL
    https://docs.google.com/spreadsheets/d/17Ea_eD4e63OKPFrRtjtwPMh7seIqc6JUF1HsHrCpul/edit#gid=0
    # Sheets document id
    17Ea_eD4e63OKPFrRtjtwPMh7seIqc6JUF1HsHrCpul
  7. Let's start the work!

Functions

authorizeGoogle(secretsPath, tokenPath)

If the tokenPath contains the JSON file with token, reads the stored token and returns the authorized OAuth2 client. Otherwise, gets and creates new token in the destination determined by tokenPath after prompting for user authorization, and then returns authorized OAuth2 client.

  • @param {String} secretsPath Path to the JSON formatted file containing the client ID, client secret, and other OAuth 2.0 parameters
  • @param {String} tokenPath Path to the JSON formatted file containing a token or path to create it.
  • @returns {google.auth.OAuth2} The authorized OAuth2 client

downloadS3Data(bucketName, objectKey, dataEncoding)

Downloads specified S3 object containing CSV/TSV file

  • @param {String} bucketName Name of the S3 bucket
  • @param {String} objectKey Object key (or key name) that identifies the object in the bucket
  • @param {String} dataEncoding Data encoding to convert the S3 object body from a Buffer to a String - e.g. "utf-8", "base64", "ascii"
  • @returns {String} String representing data from downloaded CSV/TSV file

processS3Data(downloadedData, dataSepratator)

Processes downloaded CSV/TSV data for proper representation for Google Sheets

  • @param {String} downloadedData String representing data from downloaded CSV/TSV file
  • @param {String} dataSepratator Name of the separator that is used to separate values in the CSV/TSV file - can be only "comma" or "tab"
  • @returns {any} Processed data that are prepared to be written to Google Sheets

appendGoogleSheet(version, auth, id, range, inputOption, resource)

Appends processed data to the specified spreadsheet

  • @param {String} version Version of the google sheets API
  • @param {oAuth2Client} auth The authorized OAuth2 client
  • @param {String} id The ID of the spreadsheet to update
  • @param {String} range The A1 notation of a range to search for a logical table of data. Values are appended after the last row of the table
  • @param {String} inputOption How the input data should be interpreted - can be only "INPUT_VALUE_OPTION_UNSPECIFIED", "RAW", or "USER_ENTERED"
  • @param {any} resource The processed data that are prepared to be written to the spreadsheet
  • @returns {any} The append values response

clearAndUpdateGoogleSheet(version, auth, id, range, inputOption, resource)

Clears the whole spreadsheet and subsequently inserts processed data to the spreadsheet

  • @param {String} version Version of the google sheets API
  • @param {oAuth2Client} auth The authorized OAuth2 client
  • @param {String} id The ID of the spreadsheet to update
  • @param {String} range The A1 notation of a range to search for a logical table of data. Values are appended after the last row of the table
  • @param {String} inputOption How the input data should be interpreted - can be only "INPUT_VALUE_OPTION_UNSPECIFIED", "RAW", or "USER_ENTERED"
  • @param {any} resource The processed data that are prepared to be written to the spreadsheet
  • @returns {any} The clear or update values response

updateGoogleSheet(version, auth, id, range, inputOption, resource)

Updates spreadsheet with the processed data

  • @param {String} version Version of the google sheets API
  • @param {oAuth2Client} auth The authorized OAuth2 client
  • @param {String} id The ID of the spreadsheet to update
  • @param {String} range The A1 notation of a range to search for a logical table of data. Values are appended after the last row of the table
  • @param {String} inputOption How the input data should be interpreted - can be only "INPUT_VALUE_OPTION_UNSPECIFIED", "RAW", or "USER_ENTERED"
  • @param {any} resource The processed data that are prepared to be written to the spreadsheet
  • @returns {any} The update values response

Usage

```javascript
const {sheetsUploader} = require('@danse4mobility/google-sheets-uploader');

const secretsPath = 'client_secret.json';
const tokenPath = 'token.json';
const bucketName = "sheetstack-mybucket123a-1123";
const objectKey = "data.csv";
const encoding = "utf-8";
const dataSeparator = "comma"; // supported values are "comma" or "tab"
const version = "v4";
const id = "17Ea_eD4e63OKPFrRtjtwPMh7seIqc6JUF1HsHrCpul";
const range = "A1:K";
const inputOption = "RAW"; // supported values are "INPUT_VALUE_OPTION_UNSPECIFIED", "RAW" or "USER_ENTERED"


var oAuth2Client = await sheetsUploader.authorizeGoogle(secretsPath, tokenPath);
var downloadedData = await sheetsUploader.downloadS3Data(bucketName, objectKey, encoding);
var resource = await sheetsUploader.processS3Data(downloadedData, dataSepratator);
var response = await sheetsUploader.clearAndUpdateGoogleSheet(version, oAuth2Client, id, range, inputOption, resource);
console.log(response);
```

Changelog

  • 0.1.0: Initial release

License

Module is MIT -licensed