Instantly share code, notes, and snippets.

Embed
What would you like to do?
Be sure to `node install request mongodb` before you run this
var request = require('request')
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
// Connection URL
var url = 'mongodb://localhost:27017/spike';
// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
var collection = db.collection('tv_shows');
console.log("Connected successfully to server");
["http://api.tvmaze.com/singlesearch/shows?q=hbo&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=dexter&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=shameless&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=mr-robot&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=prison-break&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=gravity-falls&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=modern-family&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=Ray-Donovan&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=better-call-saul&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=Homeland&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=silicon-valley&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=breaking-bad&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=the-walking-dead&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=south-park&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=Futurama&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=game-of-thrones&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=lost&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=24&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=prison-break&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=house-of-cards&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=seinfeld&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=gotham&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=friends&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=how-i-met-your-mother&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=greys-anatomy&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=flash&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=game-of-thrones&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=arrow&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=legends-of-tomorrow&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=big-bang-theory&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=friends&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=flash&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=arrow&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=supergirl&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=quantico&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=sherlock&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=Pitchers&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=narcos&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=black-mirror&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=stranger-things&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=rick-&-morty&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=steven-universe&embed=episodes",
"http://api.tvmaze.com/singlesearch/shows?q=westworld&embed=episodes"].forEach(function(url){
request(url, function(err, response, body){
collection.insertOne(JSON.parse(body), function(err, result) {
assert.equal(err, null);
console.log("Inserted a document into the shows collection.");
});
// console.log(body);
});
});
// db.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment