Skip to content

Instantly share code, notes, and snippets.

@fbslo
Last active December 6, 2020 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbslo/7dfae1b50136a3fc16560903685fa4fb to your computer and use it in GitHub Desktop.
Save fbslo/7dfae1b50136a3fc16560903685fa4fb to your computer and use it in GitHub Desktop.
bitcoiner
var Twit = require('twit')
const CONSUMER_KEY=''
const CONSUMER_SECRET=''
const ACCESS_TOKEN=''
const ACCESS_TOKEN_SECRET=''
var T = new Twit({
consumer_key: CONSUMER_KEY,
consumer_secret: CONSUMER_SECRET,
access_token: ACCESS_TOKEN,
access_token_secret: ACCESS_TOKEN_SECRET,
timeout_ms: 60*1000, // optional HTTP request timeout to apply to all requests.
strictSSL: true, // optional - requires SSL certificates to be valid.
})
const guesses = []
const target = 100
const numberPattern = /\d+/g;
// T.get('statuses/show/:id', { id: '1335345136197234688' }, function(err, data, response) {
// //console.log(data)
// })
T.get('statuses/mentions_timeline', { since_id: '1335345136197234688' }, function(err, data, response) {
if (data) {
data.forEach(function(mention) {
if (mention.user.screen_name != '_bitcoiner' && mention.retweeted == false){
guesses.push(mention)
}
})
processData()
}
})
function processData(){
const filter = guesses.filter((thing, index, self) =>
index === self.findIndex((t) => (
t.screen_name === thing.screen_name
))
)
const numbers = []
filter.forEach(data => {
let num = data.text.match( numberPattern )
if (!num) return;
let dif = num - target
if (dif < 0) dif * -1
numbers.push({
username: data.screen_name,
num: num,
difference: dif
})
})
let winner = numbers.reduce(function(prev, curr) {
return prev.difference > curr.difference ? prev : curr;
});
console.log(winner)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment