Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var json2csv = require('json2csv');
- var Twitter = require('twitter');
- var fs = require('fs');
- var config = require('config-ini');
- var client = new Twitter({
- consumer_key: 'o6l6EcQw4YG1ZXRhhGzchLLz2',
- consumer_secret: 'tPoeRTnxRxWoQlBULwfpP3m4lM66oZC1FvCQmJOAXa7UUniK60',
- access_token_key: '1956342835-Fk9rvWPflfIeZnNVn20sEHcweXHs0wdrRWVaMLm',
- access_token_secret: 'uDw3tlNEj3k4kiL7xQo6OeTaNF9HmyBPd3mbfXY6O0xHq'
- });
- config.load(['config.ini'], function(err) {
- if (err) {
- throw new Error(err); //File not found
- }
- lang = config.lang.language;
- fileLocation = config.file.location;
- location = config.location.name;
- key = config.keywords.wordsToFilter;
- //console.log(key);
- myFunction(key, lang, fileLocation, location);
- });
- function myFunction(keywords, language2, fileLocation, location) {
- client.stream('statuses/filter', { track: keywords, language: language2 }, function(stream) {
- stream.on('data', function(tweet) {
- if (typeof tweet.user !== 'undefined') {
- if (location = '') {
- console.log(tweet.text);
- var tex = tweet.text;
- var text = tex.replace(/(\r\n|\n|\r)/gm," ");
- var text2 = text.replace(/,/g, " ");
- if(check(text2))
- {
- fs.appendFile(fileLocation, "\r\n"+tweet.created_at+','+tweet.id+','+tweet.id_str+','+text2+','+tweet.source+','+tweet.truncated+','+tweet.in_reply_to_status_id+','+tweet.in_reply_to_status_id_str+','+tweet.in_reply_to_user_id+','+tweet.in_reply_to_user_id_str+','+tweet.in_reply_to_screen_name+','+tweet.user.id+','+tweet.user.id_str+','+tweet.user.name+','+tweet.user.screen_name+','+tweet.user.location+','+tweet.user.url+','+tweet.user.description+','+tweet.user.protected+','+tweet.user.verified+','+tweet.user.followers_count+','+tweet.user.friends_count+','+tweet.user.listed_count+','+tweet.user.favourites_count+','+tweet.user.statuses_count+','+tweet.user.created_at+','+tweet.user.utc_offset+','+tweet.user.time_zone+','+tweet.user.geo_enabled+','+tweet.user.lang+','+tweet.user.contributors_enabled+','+tweet.user.is_translator+','+tweet.user.profile_backgroun_color+','+tweet.user.profile_background_image_url+','+tweet.user.profile_background_image_url_https+','+tweet.user.profile_background_tile+','+tweet.user.profile_link_color+','+tweet.user.profile_sidebar_border_color+','+tweet.user.profile_sidebar_fill_color+','+tweet.user.profile_text_color+','+tweet.user.profile_use_background_image+','+tweet.user.profile_image_url+','+tweet.user.profile_image_url_https+','+tweet.user.profile_banner_url+','+tweet.user.default_profile+','+tweet.user.default_profile_image+','+tweet.user.following+','+tweet.user.follow_request_sent+','+tweet.user.notifications+','+tweet.geo+','+tweet.coordinates+','+tweet.place+','+tweet.contributors+','+tweet.retweet_count+','+tweet.favorite_count+','+tweet.entities.hashtags+','+tweet.entities.trends+','+tweet.entities.urls+','+tweet.entities.user_mentions+','+tweet.entities.symbols+','+tweet.favorited+','+tweet.retweeted+','+tweet.possibly_sensitive+','+tweet.filter_level+','+tweet.lang+','+tweet.timestamp_ms, function(err) {
- if (err) {
- return console.log(err);
- }
- console.log("*****************************************");
- });
- }
- }
- else {
- if (tweet.user.location == location) {
- console.log(tweet.text);
- ///\r?\n|\r/g, " "
- var tex = tweet.text;
- var text = tex.replace(/(\r\n|\n|\r)/gm," ");
- var text2 = text.replace(/,/g, " ");
- if(check(text2))
- {
- fs.appendFile(fileLocation, "\r\n"+tweet.created_at+','+tweet.id+','+tweet.id_str+','+text2+','+tweet.source+','+tweet.truncated+','+tweet.in_reply_to_status_id+','+tweet.in_reply_to_status_id_str+','+tweet.in_reply_to_user_id+','+tweet.in_reply_to_user_id_str+','+tweet.in_reply_to_screen_name+','+tweet.user.id+','+tweet.user.id_str+','+tweet.user.name+','+tweet.user.screen_name+','+tweet.user.location+','+tweet.user.url+','+tweet.user.description+','+tweet.user.protected+','+tweet.user.verified+','+tweet.user.followers_count+','+tweet.user.friends_count+','+tweet.user.listed_count+','+tweet.user.favourites_count+','+tweet.user.statuses_count+','+tweet.user.created_at+','+tweet.user.utc_offset+','+tweet.user.time_zone+','+tweet.user.geo_enabled+','+tweet.user.lang+','+tweet.user.contributors_enabled+','+tweet.user.is_translator+','+tweet.user.profile_backgroun_color+','+tweet.user.profile_background_image_url+','+tweet.user.profile_background_image_url_https+','+tweet.user.profile_background_tile+','+tweet.user.profile_link_color+','+tweet.user.profile_sidebar_border_color+','+tweet.user.profile_sidebar_fill_color+','+tweet.user.profile_text_color+','+tweet.user.profile_use_background_image+','+tweet.user.profile_image_url+','+tweet.user.profile_image_url_https+','+tweet.user.profile_banner_url+','+tweet.user.default_profile+','+tweet.user.default_profile_image+','+tweet.user.following+','+tweet.user.follow_request_sent+','+tweet.user.notifications+','+tweet.geo+','+tweet.coordinates+','+tweet.place+','+tweet.contributors+','+tweet.retweet_count+','+tweet.favorite_count+','+tweet.entities.hashtags+','+tweet.entities.trends+','+tweet.entities.urls+','+tweet.entities.user_mentions+','+tweet.entities.symbols+','+tweet.favorited+','+tweet.retweeted+','+tweet.possibly_sensitive+','+tweet.filter_level+','+tweet.lang+','+tweet.timestamp_ms, function(err) {
- if (err) {
- return console.log(err);
- }
- console.log("*****************************************");
- });
- }
- }
- }
- }
- });
- stream.on('error', function(error) {
- throw error;
- });
- });
- }
- function check(str){
- if(typeof(str)!=='string'){
- return false;
- }
- for(var i=0;i<str.length;i++){
- if(str.charCodeAt(i)>127 || str.charCodeAt(i)==0 || str.charCodeAt(i)>0 && str.charCodeAt(i)<32 ) {
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement