-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·62 lines (52 loc) · 1.16 KB
/
index.js
File metadata and controls
executable file
·62 lines (52 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
var imdb = require('imdb-api')
var Table = require('cli-table')
// extracted fields
var fields = [
'title',
'type',
'year',
'genres',
'director',
'actors',
'plot',
'rating',
'votes'
]
// istantiate table
var table = new Table()
var title = process.argv.slice(2).join(' ')
if (!title.length) {
console.log('Please provide a valid Title.')
process.exit(1)
}
console.log('Searching for:', title)
// get movie info from IMDB
imdb.get(title)
.then(function (data) {
if (data.type === 'movie') {
var filteredData = cleanProps(data)
Object.keys(filteredData).forEach(function (i) {
var row = {}
row[i] = filteredData[i]
table.push(row)
})
console.log(table.toString())
} else {
console.log('No movie found!')
}
})
.catch(function (err) {
console.log(err)
})
/* util functions */
function cleanProps (obj) {
var newObj = {}
fields.forEach(function (k) {
if (obj.hasOwnProperty(k)) newObj[k] = limitChars(obj[k])
})
return newObj
}
function limitChars (data) {
return (data.length > 60) ? data.slice(0, 57) + '...' : data
}