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

google-trends-cli

v0.3.0

Published

Impromptu Google Trends api! Warning, WIP.

Downloads

7

Readme

Google Trends API Client!

Ever wanted the data from Google Trends in json format? You're in luck!

This client uses and simplifies the google trends API so you can create easy queries, while also allowing for the scalability of multiple searches. Perfect for data-scientists who need lots of trends simultaneously!


1) Install

Make sure you have Node installed. Then run

npm install google-trends-cli

or

yarn add google-trends-cli

yarn is always safer, but hey if you're used to using npm then go for it. I'm not gonna stop you.


2) Usage

Create a file names index.js and place this in it:

 // load the library and associated option values
 const { TrendsClient, TIME_RANGES, GEOS } = require("google-trends-cli");
 
 // must be in an asynchronous function
 (async () => {try {
   // initialize new client
   const trendsCli = new TrendsClient();
   // Authorize specific query
   const query = {
     keyword: "Hello",
     geo: GEOS.UNITED_STATES,
     time: TIME_RANGES.PAST_7_DAYS,
   }
   trendsCli.toggleAll(true)
   const response = await trendsCli.Query(query);
   console.log(response);
 } catch(e) {
   console.log(e)
 }})()

In your terminal, run node index.js. If it responds with a list of data items, congratulations! You did it sport.

TrendsClient Methods

1) new TrendsClient({ cookie })

Initializes a new Google Trends Client. The cookie optional argument passed in is just a NID cookie, necessary for Authorizing query request. If cookie isn't supplied, Google Trends Client gets one from host google.com. Example NID cookie: "NID=205=dvwJyLE9N3dGUfsmwLik56lFe9Bgk0snFGU3sziiC2yiq4uEe06OqHX2sSzo5SVXeGRL2ap7A1prutPpceJpG5_kYVpEvLiMCEvcyn6_qPPWYgU5vD7ZKnb7iqBVUjN85zRlGa6gaVTui9nWFzOwdk2q7_cr_V7h8E7eynntYJM; expires=Sat, 26-Jun-2021 01:28:49 GMT; path=/; domain=.google.com; HttpOnly"

2) toggleAll(toggle)

This method toggles all the different widget possibilities so that when the Query method is called, these data items are returned. Optional toggle methods that are similar to this one (but only toggle one widget at a time) are toggleTimeline, toggleGeoMap, toggleRelatedQueries, and toggleRelatedTopics.

3) Query({ keyword, keywords, geo, time, category }) => widgets

variables:

| Option | Default | Type | Description | Example | |:--------:|:-----------------------:|:-------:|:----------------------:|-------------| | keyword | "" | string | keyword to query for | "Hello" | | keywords | [ "" ] | Array | keywords to query and compare against each other | [ "Hello", "Hi" ] | | geo | GEOS.ALL | string | Geographic zone to query for. All GEO values allowed are located here | GEOS.UNITED_STATES | | time | TIME_RANGES.PAST_7_DAYS | string | Time range to query for. All Time range values are located here| TIME_RANGES.CUSTOM("11/24/20", "12/24/20") | | category | CATEGORIES.ALL | string | Category to query for. All category values allowed are located here | CATEGORIES.ARTS_ENTERTAINMENT | | widgets | undefined | Array | response widget. A widget has an error property if something went wrong and a data property if the data was successfully retrieved. | { data: { timelineData: { ... } } } |