├── LICENSE ├── index.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tomasz Baranowicz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Twit = require('twit') 2 | const notifier = require('node-notifier'); 3 | const open = require('open'); 4 | const franc = require('franc') 5 | 6 | const apikey = 'xxx' 7 | const apiSecretKey = 'xxx' 8 | const accessToken = 'xxx' 9 | const accessTokenSecret = 'xxx' 10 | 11 | var T = new Twit({ 12 | consumer_key: apikey, 13 | consumer_secret: apiSecretKey, 14 | access_token: accessToken, 15 | access_token_secret: accessTokenSecret, 16 | }); 17 | 18 | (async () => { 19 | 20 | // //1. GET RECENT TWEETS 21 | // T.get('search/tweets', { q: '#tesla since:2020-04-15', count: 100 }, function(err, data, response) { 22 | // const tweets = data.statuses 23 | // // .map(tweet => `LANG: ${franc(tweet.text)} : ${tweet.text}`) //CHECK LANGUAGE 24 | // .map(tweet => tweet.text) 25 | // .filter(tweet => tweet.toLowerCase().includes('elon')); 26 | // console.log(tweets); 27 | // }) 28 | 29 | // //2. REAL TIME MONITORING USING STREAM (HASHTAG) 30 | // var stream = T.stream('statuses/filter', { track: '#tesla' }) 31 | // stream.on('tweet', function (tweet) { 32 | // console.log(tweet.text); 33 | // console.log('Language: ' + franc(tweet.text)); 34 | // console.log('------'); 35 | // }) 36 | 37 | // 3. REAL TIME MONITORING USING STREAM (LOCATION) 38 | var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ] 39 | var stream = T.stream('statuses/filter', { locations: sanFrancisco }) 40 | 41 | //SHOW NOTIFICATION FOR EACH RECEIVED TWEET 42 | stream.on('tweet', function (tweet) { 43 | console.log(tweet.text); 44 | let url = `https://twitter.com/${tweet.user.screen_name}/status/${tweet.id_str}` 45 | 46 | notifier.notify({ 47 | title: tweet.user.name, 48 | message: tweet.text 49 | }); 50 | 51 | notifier.on('click', async function(notifierObject, options, event) { 52 | console.log('clicked'); 53 | await open(url); 54 | }); 55 | }) 56 | })(); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twitter-monitoring", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Tom Baranowicz", 10 | "license": "ISC", 11 | "dependencies": { 12 | "franc": "^5.0.0", 13 | "node-notifier": "^7.0.0", 14 | "open": "^7.0.3", 15 | "twit": "^2.2.11" 16 | } 17 | } 18 | --------------------------------------------------------------------------------