-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (23 loc) · 911 Bytes
/
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
// Get auth data
const config = require('./config.js')
// Load Twiiter library
const Twitter = require('twitter-node-client').Twitter
const twitter = new Twitter(config)
// Callback functions
const error = (err, response, body) => {
console.log('ERROR: ', err)
};
const success = data => {
const { statuses } = JSON.parse(data)
const totalTweets = statuses.length
const randomPosition = Math.floor(Math.random() * totalTweets)
const selectedTweet = statuses[randomPosition]
console.log('\nCANDIDATE TWEETS')
statuses.forEach(status =>
console.log(`https://twitter.com/${status.user.screen_name}/status/${status.id_str}`)
)
console.log('\nAND THE WINNER IS...')
console.log(`https://twitter.com/${selectedTweet.user.screen_name}/status/${selectedTweet.id_str}`)
};
// Search command
twitter.getSearch({q:'#frontfest18 since:2018-02-12 -filter:retweets', count: 100}, error, success)