Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tng json
#!/usr/bin/env bash
wget http://www.chakoteya.net/NextGen/{101..277}.htm
#!/usr/bin/env ruby
require 'mongo'
client = Mongo::Client.new(["ds047592.mongolab.com:47592"], :database => "webtask-examples", :user => "webtask", :password => "supersecret")
episodes = Dir["*.htm"].map do |filename|
{ :episode => filename, :data => File.read(filename).scrub }
end
client[:startrek_episodes].insert_many(episodes)
//var data = require("./tng.json")
var cheerio = require('cheerio')
var url = "https://gist.githubusercontent.com/ChrisLundquist/7c6579c381e0207cbf239e501ba3375c/raw/50616db112a901b3620f18c71983d362a57ab620/tng.json"
var request = require('request');
function findMatches(data, query) {
matches = []
for (var i in data) {
if(!query.test(data[i].data))
continue;
html = cheerio.load(data[i].data)
episode_name = html("body p font b")[0].children[0].data
matches += (episode_name.replace(/(\r\n|\n|\r)/gm," ") + "\n")
}
return matches
}
//module.exports = function(ctx, cb) {
// var query = new RegExp(ctx.data.q, 'i');
var query = /captain picard day/i
request(url, function (error, response, html) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(html)
matches = findMatches(data, query)
console.log(matches);
}
});
//}
This file has been truncated, but you can view the full file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment