Last active
July 10, 2017 23:16
-
-
Save tannerwelsh/008bd8480a011dc24260430d7ee06ae0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rp = require('request-promise') | |
const cheerio = require('cheerio') | |
const buildURL = (searchQuery) => { | |
return `http://www.imdb.com/find?q=${searchQuery}&s=tt&ref_=fn_al_tt_mr` | |
} | |
const parseResults = ($) => { | |
return $('td.result_text') | |
.map((i, el) => $(el).text().replace(/ - /g, "\n - ")) | |
.get() | |
} | |
const loadWithCheerio = (body) => cheerio.load(body) | |
const searchIMDB = (query) => { | |
const uri = buildURL(query) | |
const options = { uri, transform: loadWithCheerio } | |
return rp(options).then(parseResults) | |
} | |
if (!module.parent) { | |
const queryTerm = process.argv[2] | |
searchIMDB(queryTerm).then((results) => { | |
console.log(results.join("\n")) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "movie-search-cli", | |
"description": "Search for movies on IMDB w/ CLI", | |
"main": "imdb.js", | |
"dependencies": { | |
"cheerio": "^1.0.0-rc.2", | |
"request": "^2.81.0", | |
"request-promise": "^4.2.1" | |
}, | |
"author": "Tanner Welsh" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment