Giter Site home page Giter Site logo

g-trends's Introduction

G Trends

A simple API client for Google Trends.

Quick Start

npm install g-trends

Super simple to use

G Trends client is designed to be the simplest way for developers to access Google Trends data.

const { ExploreTrendRequest } = require('g-trends')

const explorer = new ExploreTrendRequest()

explorer.addKeyword('Dream about snakes')
        .compare('Dream about falling')
        .download().then( csv => {
            console.log('[✔] Done, take a look at your beautiful CSV formatted data!')
            console.log(csv)
        }).catch( error => {
            console.log('[!] Failed fetching csv data due to an error',error)
        })
[✔] Done, take a look at your beautiful CSV formatted data!
[ [ 'Day',
    'Dream about snakes: (Worldwide)',
    'Dream about falling: (Worldwide)' ],
  [ '2017-09-29', '26', '58' ],
  [ '2017-09-30', '68', '88' ],
  [ '2017-10-01', '57', '100' ],
  [ '2017-10-02', '72', '60' ],
  [ '2017-10-03', '65', '70' ],
  [ '2017-10-04', '35', '55' ],
  [ '2017-10-05', '55', '58' ],
  [ '2017-10-06', '34', '80' ],
  [ '2017-10-07', '66', '69' ],
  ...

ExploreTrendRequest

Method Listing

normalize()

the normalize method give you a quick way to overwrite the default normalization function and process the raw Google Trends data before it resolved.

const explorer = new ExploreTrendRequest()
explorer.normalize( raw => raw.split("\n") ).addKeyword('dogs').

searchProvider()

The searchProvider method allow you to choose the search provider you wise to extract data from.

const { ExploreTrendRequest,SearchProviders } = require('g-trends')

const explorer = new ExploreTrendRequest()

// SearchProviders.News, SearchProviders.Web, SearchProviders.YouTube
// SearchProviders.GoogleImages, SearchProviders.GoogleShopping

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .download().then( csv => {
            console.log('[✔] Done, take a look at your beautiful CSV formatted data!')
            console.log(csv)
        }).catch( error => {
            console.log('[!] Failed fetching csv data due to an error',error)
        })

addKeyword()

The addKeyword method appends a given keywords to the trend exploration request.

const explorer = new ExploreTrendRequest()

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

between()

The between method allows you to extract trend data for a given time period.

const explorer = new ExploreTrendRequest()

explorer.searchProvider(SearchProviders.News)
        .addKeyword('Bitcoin')
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .between('2017-01-01','2017-01-10')
        .download().then( csv => {
            console.log(csv)
        })

pastHour()

The pastHour method allows you to extract trend data for a the past hour.

explorer.pastHour()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

pastFourHours()

The pastFourHours method allows you to extract trend data for a the past 4 hours.

explorer.pastFourHours()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

pastDay()

The pastDay method allows you to extract trend data for a the past day.

explorer.pastDay()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past7Days()

The past7Days method allows you to extract trend data for a the past 7 days.

explorer.past7Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past30Days()

The past30Days method allows you to extract trend data for a the past 30 days.

explorer.past30Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past90Days()

The past90Days method allows you to extract trend data for a the past 90 days.

explorer.past90Days()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past12Months()

The past12Months method allows you to extract trend data for a the past 12 months.

explorer.past12Months()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

past5Years()

The past5Years method allows you to extract trend data for a the past 5 years.

explorer.past5Years()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

from2004ToPresent()

The from2004ToPresent method allows you to extract trend data from 2004 to the present.

explorer.from2004ToPresent()
        .addKeyword('Cats')
        .addKeyword('Dogs')
        .download().then( csv => {
            console.log(csv)
        })

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.