Advertisement
Guest User

Untitled

a guest
May 27th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var json2csv = require('json2csv');
  2. var Twitter = require('twitter');
  3. var fs = require('fs');
  4. var config = require('config-ini');
  5. var client = new Twitter({
  6.     consumer_key: 'o6l6EcQw4YG1ZXRhhGzchLLz2',
  7.     consumer_secret: 'tPoeRTnxRxWoQlBULwfpP3m4lM66oZC1FvCQmJOAXa7UUniK60',
  8.     access_token_key: '1956342835-Fk9rvWPflfIeZnNVn20sEHcweXHs0wdrRWVaMLm',
  9.     access_token_secret: 'uDw3tlNEj3k4kiL7xQo6OeTaNF9HmyBPd3mbfXY6O0xHq'
  10. });
  11.  
  12. config.load(['config.ini'], function(err) {
  13.     if (err) {
  14.         throw new Error(err); //File not found
  15.     }
  16.     lang = config.lang.language;
  17.     fileLocation = config.file.location;
  18.     location = config.location.name;
  19.     key = config.keywords.wordsToFilter;
  20.     //console.log(key);
  21.     myFunction(key, lang, fileLocation, location);
  22. });
  23.  
  24. function myFunction(keywords, language2, fileLocation, location) {
  25.     client.stream('statuses/filter', { track: keywords, language: language2 }, function(stream) {
  26.         stream.on('data', function(tweet) {
  27.             if (typeof tweet.user !== 'undefined') {
  28.                 if (location = '') {
  29.                     console.log(tweet.text);
  30. var tex = tweet.text;
  31. var text = tex.replace(/(\r\n|\n|\r)/gm," ");
  32.  var text2 = text.replace(/,/g, " ");
  33.  
  34. if(check(text2))
  35. {
  36.                     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) {
  37.                         if (err) {
  38.                             return console.log(err);
  39.                         }
  40.  
  41.                         console.log("*****************************************");  
  42.                     });
  43. }
  44.                 }
  45.                 else {
  46.                     if (tweet.user.location == location) {
  47.                         console.log(tweet.text);
  48.  
  49. ///\r?\n|\r/g, " "
  50. var tex = tweet.text;
  51. var text = tex.replace(/(\r\n|\n|\r)/gm," ");
  52.  var text2 = text.replace(/,/g, " ");
  53. if(check(text2))
  54. {
  55.                         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) {
  56.                             if (err) {
  57.                                 return console.log(err);
  58.                             }
  59.                             console.log("*****************************************");
  60.                         });
  61. }
  62.                     }
  63.                 }
  64.             }
  65.         });
  66.         stream.on('error', function(error) {
  67.             throw error;
  68.         });
  69.     });
  70. }
  71.  
  72. function check(str){
  73.     if(typeof(str)!=='string'){
  74.         return false;
  75.     }
  76.     for(var i=0;i<str.length;i++){
  77.         if(str.charCodeAt(i)>127 || str.charCodeAt(i)==0 || str.charCodeAt(i)>0 && str.charCodeAt(i)<32 ) {
  78.             return false;
  79.         }
  80.     }
  81.     return true;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement