0

I'm trying to get all the messages from a Twitter account and add them to a database. Half the script works, it shows the messages in console if the console.log is outside function.

But when trying to loop all the messages and adding them in the database by inserting console.log like bellow in function con.query it outputs only the last tweet as a duplicate.

Please try and keep the response as simple as you can, I'm not that good at programing. Thank you

for (var i = 0; i < data.length ; i++) { // get all the messages from username, devfined in search term



            var tweet = data[i]; // full retweet info
            var retweetId = data[i].id; // id
            var retweetId_str = data[i].id_str; // id_str = id not rounded more precise
            var tweetTextVanilla = data[i].text; // tweet text

            var tweetDatetoString = data[i].created_at; // retweet date
            var tweetDate = new Date(tweetDatetoString);
            var date = dateFormat(tweetDate, 'yyyy-mm-dd hh:MM:ss'); 



        con.query('SELECT retweetid_str FROM droid_retweets WHERE retweetId_str=?', retweetId_str, function(error,result){ // Search for retweet id if exist on database


            if(result == 0){// true, value is not in the database
                console.log('Tweet will be added in the database');

                console.log('Retweet Content : ', tweetTextVanilla, 'Last insert - id:', retweetId,' id_str:', retweetId_str, 'into line -', 'at date -', date);  

            }else{          // false, value is in database
                console.log('Tweet exist in the database, will not proceed adding it in.');
            }


        }); 


    } // for close
Alex _TNT
  • 309
  • 1
  • 2
  • 12

0 Answers0