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-downloader

v1.1.4

Published

Google sheets downloader

Downloads

4

Readme

google-sheets-downloader

An unofficial client intended to download the content of a Google Sheets spreadsheet and subsequently upload its content as an AWS S3 object.

Table of contents

Getting Started

  1. Install module

    npm install @danse4mobility/google-sheets-downloader
  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

getSpreadsheetData(version, auth, id)

Gets information about a specific Google 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
  • @returns {any} Properties of the spreadsheet sheets

downloadGoogleSheet(version, auth, id, range)

Downloads specific 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
  • @returns {any} Downloaded data from the spreadsheet

processGoogleSheetData(downloadedData, headerArrayLength)

Processes downloaded data for proper representation in S3 storage

  • @param {any} downloadedData The data that was read. This is an array of arrays, the outer array representing all the data and each inner array representing a major dimension. Each item in the inner array corresponds with one cell.
  • @param {number} headerArrayLength Length of the array header
  • @returns {any} Processed data that are prepared to be written to S3 storage

uploadDataToS3(bucketName, objectKey, processedData)

Uploads processed data to the specified S3 object

  • @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} processedData Processed data that are prepared to be written to S3 storage
  • @returns {String} The location that identifies the newly created object

Usage

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

const secretsPath = 'client_secret.json';
const tokenPath = 'token.json';
const version = "v4";
const id = "17Ea_eD4e63OKPFrRtjtwPMh7seIqc6JUF1HsHrCpul";
const range = "A1:K";
const headerArrayLength = 7;
const bucketName = "sheetstack-mybucket123a-1123";
const objectKey = "data.csv";


var oAuth2Client = await sheetsDownloader.authorizeGoogle(secretsPath, tokenPath);
var downloadedData = await sheetsDownloader.downloadGoogleSheet(version, oAuth2Client, id, range);
var processedData = await sheetsDownloader.processGoogleSheetData(downloadedData, headerArrayLength);
var location = await sheetsDownloader.uploadDataToS3(bucketName, objectKey, processedData);
console.log(location);
```

Changelog

  • 1.1.0: getSpreadsheetData method added
  • 1.0.0: First version release
  • 0.1.0: Initial release

License

Module is MIT -licensed