This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·65 lines (55 loc) · 1.57 KB
/
index.js
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
63
64
65
#!/usr/bin/env node
const commandLineArgs = require('command-line-args')
const getTweets = require('./lib/get_tweets.js')
const debug = require('debug')('recent-tweets')
const readline = require('readline')
const showUsage = () => {
const message = 'twls [options...] twitter_username'
process.stdout.write(message)
process.stdout.write('\n')
}
const main = async options => {
try {
debug(`getting recent tweets for ${options.username}`)
const tweets = await getTweets(options.username, {
expandShortlinks: options['expand-shortlinks'],
deviceDescriptor: options.device
})
process.stdout.write(JSON.stringify(tweets))
process.stdout.write('\n')
} catch (error) {
console.error(error)
}
}
if (require.main === module) {
let options
try {
options = commandLineArgs([
{ name: 'username', alias: 'u', type: String, defaultOption: true },
{ name: 'expand-shortlinks', alias: 'x', type: Boolean, defaultValue: false },
{ name: 'device', alias: 'd', type: String, defaultValue: 'iPhone 11 Pro Max' }
])
debug(`options: ${JSON.stringify(options, null, 2)}`)
} catch (error) {
options = undefined
process.exitCode = -2
showUsage()
}
if (options) {
if (!options.username) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.on('line', async username => {
options.username = username
main(options)
})
} else {
main(options)
}
}
} else {
debug('required as a module')
}
module.exports = getTweets