SmartBlocks icon indicating copy to clipboard operation
SmartBlocks copied to clipboard

Google Trends SmartBlock

Open mlava opened this issue 5 years ago • 0 comments

✂️ Copy of your #42SmartBlock from Roam

Google Trends SmartBlock.zip

📋 Describe the SmartBlock

SmartBlock to retrieve Daily Trends or Category Realtime trends from Google Trends.

Part of a set of SmartBlocks written to fulfil a bounty requested by Ekim Nazim Kaya: https://roamresearch.com/#/app/roambounties/page/01-09-2021

Hacker News - Google Trends - Product Hunt - Reddit - Twitter Trending

✅ Describe any prerequisites or dependencies that are required for this SmartBlock

Roam42.

Requires creation of a node.js server. I did this on heroku: https://devcenter.heroku.com/articles/getting-started-with-nodejs

The address of the node.js API server needs to be supplied in the configuration settings.

Included CSS to allow horizontal/grid display of results sub-blocks. Also includes a button for placement in Daily Notes templates.

📷 Screenshot of your #42SmartBlock workflow/template from Roam

image

Each item has sub-blocks containing a summary, representative image and link to a news source.

💡 Additional Info

Content of app.js file in root folder of nodejs server:

const googleTrends = require('./node_modules/google-trends-api');
const express = require('express');
var cors = require('cors');
const app = express();
var port = process.env.PORT || 3000;
app.use(cors());

var corsOptions = {
  origin: 'https://roamresearch.com',
  optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}

app.get('/', cors(corsOptions), (req, res) => {
	
	var mode = req.query.mode;
	
	if (req.query.country) {
	var country = req.query.country;
	} else {
		console.log("Please supply a Country! Defaulting to US.");
		var country = "US";
	}
	
	if (mode == "DT") {
		googleTrends.dailyTrends({
		  geo: country,
		}, function(err, results) {
		  if (err) {
			console.log(err);
		  }else{
			res.json(results);
		  }
		});
	} else if (mode == "cat") {
		if (req.query.category) {
			var cat = req.query.category;
		} else {
			var cat = "all";
		}
		googleTrends.realTimeTrends({
		geo: country,
		category: cat,
		}, function(err, results) {
			if (err) {
				console.log(err);
			} else {
				 
			} 
		});
	}
})

app.listen(port, () => {
  console.log(`Listening at http://localhost:${port}`)
})

mlava avatar Feb 11 '21 09:02 mlava