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

iotdb-google

v1.1.4

Published

Pipe Oriented Programming

Downloads

3

Readme

iotdb-google

Pipe-Oriented Programming Google wrapper

Credentials

Google has a two phase process for access to its API from the command line:

  • get a credentials JSON object
  • interactively get a Token

More can be read about this here.

When you look at Credentials in the GCM console, you should see that it's in the section OAuth 2.0 client IDs.

When you download the JSON, it should look something like that, noting in particular the installed.

{
  "installed": {
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 
    "auth_uri": "https://accounts.google.com/o/oauth2/auth", 
    "client_id": "XXXX.apps.googleusercontent.com", 
    "client_secret": "XXXX", 
    "project_id": "api-access-XXXX", 
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob", 
      "http://localhost"
    ], 
    "token_uri": "https://www.googleapis.com/oauth2/v3/token"
  }
}

To use this you need to also have a token. We provide a tool here to this, e.g.

node bin/google-token.js --sheets 
node bin/google-token.js --drive
node bin/google-token.js --sheets --drive --write

Note the expectation that the credentials are in credentials.json and the token will be saved in token.json. This is changeable via command line options.

Google Sheets

See samples/sheets.js for a more worked out version of this sample.

const _ = require("iotdb-helpers")
const google = require("iotdb-google")

let credentials
let token

try {
    credentials = require("./credentials.json")
    token = require("./token.json")
} catch (x) {
    console.log("#", "use bin/google-token to get tokens first")
}

_.promise({
    googled: {
        credentials: credentials,   // loaded from somewhere
        token: token,               // loaded from somewhere
    },
})
    .then(google.initialize)
    .then(google.auth.token)
    .then(google.sheets.initialize)

    .then(google.sheets.list.p("/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/Class Data!A1:E"))
    .then(google.sheets.headers.first)

    .make(sd => {
        console.log("+", JSON.stringify(sd.jsons, null, 2))
    })
    .catch(error => {
        delete error.self
        console.log("#", error)
    })

Here's an example of manipulating the spreadsheet

_.promise({
    googled: {
        credentials: credentials,   // loaded from somewhere
        token: token,               // loaded from somewhere
    },
})
    .then(google.initialize)
    .then(google.auth.token)
    .then(google.sheets.initialize)
    .then(google.sheets.parse.p("/10Wdg2EE6TGEnOBJonFuQ5C9Kp0cZy1Lp0zA4JsSIniE"))

    .add("google$batch", true)

    // change the header
    .then(google.sheets.parse.p("Sheet1!A1:F1"))
    .then(google.sheets.cell.underline.p(true))
    .then(google.sheets.cell.background.p(_.random.choose(_.values(_.color.colord))))
    .then(google.sheets.cell.color.p(_.random.choose(_.values(_.color.colord))))

    // manipulate the first row
    .then(google.sheets.parse_range.p("A1:A7"))
    .then(google.sheets.find_replace.p(/^J.*$/, "Joseph"))

    // do all those commands at once (uses "google$batch")
    .then(google.sheets.batch)

    .make(sd => {
        console.log("+", "done")
    })
    .catch(error => {
        delete error.self
        console.log("#", error)
    })

Here's an example of exporting a Google Doc to HTML

_.promise({
    googled: googled,
})
    .then(google.initialize)
    .then(google.auth.token)
    .then(google.drive.initialize)
    .then(google.drive.file.export.p(
        "https://docs.google.com/document/d/1vgXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/edit",
        "text/html"
    ))
    .make(sd => {
        console.log("+", sd.document)
    })
    .catch(error => {
        delete error.self
        console.log("#", error)
    })