pat310 / google-trends-api

An API layer on top of google trends
https://www.npmjs.com/package/google-trends-api
MIT License
877 stars 175 forks source link

Can we add shouldIncludeTime optional ? #82

Closed aonurbilgin closed 6 years ago

aonurbilgin commented 6 years ago

Hey,

Can we add shouldIncludeTime optional just like that;

utilities.js
let shouldIncludeTime;

  if (obj.shouldIncludeTime) {
    shouldIncludeTime = isLessThan7Days(obj.startTime, obj.endTime);
  }

Sample usage;

googleTrends.interestByRegion({
  keyword: 'Donald Trump',
  startTime: new Date('2017-02-01'),
  endTime: new Date('2017-02-03'),
  resolution: 'CITY',
  shouldIncludeTime: false
})

In that way we can get only daily data from google trends. Even less than 7 days.

pat310 commented 6 years ago

@aonurbilgin I'm not seeing the daily data when I do this for the interestByRegion method. Could you post the results you are getting when you do this with the flag set to false versus set to true?

aonurbilgin commented 6 years ago

@pat310 Actualy I'm talking about interestOverTime method. Could get results per DAY. Just like that; https://trends.google.com.tr/trends/explore?date=2017-10-01%202017-10-04&geo=TR&q=ios,android

My sample usage;

const googleTrends = require('google-trends-api');

googleTrends.interestOverTime({
    keyword: ['ios', 'android'],
    startTime: new Date('2017-10-01'),
    endTime: new Date('2017-10-04'),
    geo:'TR',
    hl:'tr',
    resolution: 'DAY',
    property: 'backend',
    category: 0
}, function(err, results) {
    if (err) {
        res.status(400).send('oh no error!', err);
    } else {
        let data = JSON.parse(results);
        for(key in data) {
            console.log(data[key]);
        }
    }
});

I'm just want to get results as daily not hourly. If my date range less than 7 days isLessThan7Days function converts date range as a hourly. So in that case i cant get daily data if the date range less than 7 days.

pat310 commented 6 years ago

@aonurbilgin Gotcha, no problem I will get that in there

pat310 commented 6 years ago

@aonurbilgin Added an optional boolean granularTimeResolution to the input object. Will be available in the next release (version 4.3.0)

aonurbilgin commented 6 years ago

@pat310 Thank you