90 lines
2.5 KiB
JavaScript
90 lines
2.5 KiB
JavaScript
|
/**
|
||
|
* Created by WebStorm.
|
||
|
* User: martin
|
||
|
* Date: 30/04/2020
|
||
|
* Time: 12:24
|
||
|
|
||
|
*/
|
||
|
|
||
|
const Twitter = require('twitter-lite');
|
||
|
require('dotenv').config();
|
||
|
|
||
|
const dbmanager = require('./server/db/dbmanager');
|
||
|
|
||
|
|
||
|
const client = new Twitter({
|
||
|
'consumer_key' : process.env.TWITTER_CONSUMER_KEY,
|
||
|
'consumer_secret' : process.env.TWITTER_CONSUMER_SECRET,
|
||
|
'access_token_key' : process.env.TWITTER_ACCESS_TOKEN_KEY,
|
||
|
'access_token_secret' : process.env.TWITTER_ACCESS_TOKEN_SECRET
|
||
|
|
||
|
});
|
||
|
|
||
|
const accounts = [
|
||
|
{'name':'nationalrailenq', 'id':33546465},
|
||
|
{'name':'networkrail', 'id':365344176},
|
||
|
{'name':'NetworkRailSCOT', 'id':402687948},
|
||
|
|
||
|
{'name':'AvantiWestCoast', 'id':1143560758476906497},
|
||
|
{'name':'CalSleeper', 'id':2870293725},
|
||
|
{'name':'CrossCountryUK', 'id':153368708},
|
||
|
{'name':'Eurostar', 'id':98412169},
|
||
|
{'name':'EurostarUK', 'id':59742254},
|
||
|
{'name':'GatwickExpress', 'id':163816182},
|
||
|
{'name':'GlasgowSubway', 'id':224607925},
|
||
|
{'name':'GWRHelp', 'id':15589815},
|
||
|
{'name':'HeathrowExpress', 'id':20240678},
|
||
|
{'name':'LNER', 'id':313306238},
|
||
|
{'name':'LNRailway', 'id':910487328627535872},
|
||
|
{'name':'northernassist', 'id':194512268},
|
||
|
{'name':'ScotRail', 'id':61569136},
|
||
|
{'name':'Stansted_Exp', 'id':257511611},
|
||
|
{'name':'TfL', 'id':47319664},
|
||
|
|
||
|
{'name':'NetworkRailBHM', 'id':583910976},
|
||
|
{'name':'NetworkRailEDB', 'id':586614081},
|
||
|
{'name':'NetworkRailEUS', 'id':581807264},
|
||
|
{'name':'NetworkRailGLC', 'id':421061171},
|
||
|
{'name':'NetworkRailKGX', 'id':459192871},
|
||
|
{'name':'NetworkRailLST', 'id':581826097},
|
||
|
{'name':'NetworkRailMAN', 'id':583895871},
|
||
|
{'name':'NetworkRailVIC', 'id':587354752},
|
||
|
{'name':'BTPScotland', 'id':957256160},
|
||
|
|
||
|
];
|
||
|
|
||
|
|
||
|
(async function(){
|
||
|
/* const response = await user.getBearerToken();
|
||
|
|
||
|
const app = new Twitter({
|
||
|
bearer_token: response.access_token
|
||
|
});*/
|
||
|
|
||
|
const validAccounts = accounts.map(item => {
|
||
|
return item.id;
|
||
|
})
|
||
|
|
||
|
|
||
|
const parameters = {
|
||
|
follow: validAccounts.join(',') // Scotrail, networkrailScot, networkrail, nationalrail, tfl, avantiwestcoast
|
||
|
}
|
||
|
|
||
|
console.log('Starting:', parameters);
|
||
|
|
||
|
const stream = client.stream("statuses/filter", parameters)
|
||
|
.on("start", response => console.log('Started!'))
|
||
|
.on("data", tweet => {
|
||
|
console.log('>> data', tweet);
|
||
|
dbmanager.insertOne(tweet).then((v) => {
|
||
|
console.log(v);
|
||
|
}).catch((err) => {
|
||
|
console.error(err);
|
||
|
});
|
||
|
})
|
||
|
.on("ping", () => console.log('>> ping'))
|
||
|
.on("error", error => console.error(error))
|
||
|
.on("end", response => console.log('Stopped!'));
|
||
|
|
||
|
})();
|