not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.2 KiB

  1. const googt = require('google-trends-api');
  2. const Promise = require('promise');
  3. const DAY = 1000 * 60 * 60 * 24;
  4. module.exports=
  5. {
  6. /*
  7. desc: returns an integer score for the word over the day
  8. */
  9. getPopularity: function(word)
  10. {
  11. //must be a promise since call to trends API is async
  12. return new Promise(function(resolve, reject){
  13. //specifies the keyword, time interval, and granularity
  14. googt.interestOverTime({keyword:word,
  15. startTime:new Date(Date.now() - DAY),granularTimeResolution:true})
  16. .then(function(results){
  17. //turn into json object
  18. data = JSON.parse(results).default.timelineData;
  19. //add up values
  20. var total = 0;
  21. data.forEach(function(element){
  22. console.log(element.formattedTime + " " + element.value[0]);
  23. total += element.value[0];
  24. })
  25. //tell function to return
  26. resolve(total);
  27. }).catch(function(err){
  28. reject("Google Trends Query Failed");
  29. });
  30. });
  31. }
  32. };