Skip to content

Instantly share code, notes, and snippets.

@Amatewasu
Created January 3, 2014 22:14
Show Gist options
  • Save Amatewasu/8247683 to your computer and use it in GitHub Desktop.
Save Amatewasu/8247683 to your computer and use it in GitHub Desktop.
This little "quick & dirty" writed counts the number of characters of your tweets.
/*
* This little "quick & dirty" writed counts the number of characters of your tweets.
* Ce petit script codé rapidement et salement compte le nombre de caractères de vos tweets.
*
* How to use?
* 1) Download your Twitter archive
* 2) Install Node.js
* 3) Install the csv module, type: "(sudo) npm install csv"
* 4) Put this script in the uncompressed folder of your Twitter archive
* 5) Run the script, type "node nb_chars" in your terminal
* 6) Have fun with VERY useful stats. lulz.
*
* Comment l'utiliser ?
* 1) Téléchargez votre archive Twitter
* 2) Installez Node.js
* 3) Installez le module "csv", pour cela, tapez "(sudo) npm install csv"
* 4) Mettez ce script dans le dossier décompressé de votre archive Twitter
* 5) Lancez le script en tappant "node nb_chars" dans votre terminal
* 6) Et hop', du charabia s'affiche à l'écran, c'est le résultat.
*
* CC-BY - Alexis Delrieu
*/
console.time("delta time");
var csv = require("csv");
var nb = {
chars : 0
, charsWithoutMentions : 0
, mentions : 0
, tweetsWithMention : 0
, tweets : 0
}
csv()
.from.path(__dirname +"/tweets.csv")
.on("data", function (data){
nb.tweets++;
data = data.split(",")[5]
var words = data.split(" ");
var hasMention = false;
words.forEach(function (word){
if (word[0] == "@"){
nb.mentions++;
if (!hasMention){
hasMention = true;
nb.tweetsWithMention++;
}
} else {
nb.charsWithoutMentions += word.length + 1;
}
nb.chars += word.length + 1;
});
})
;
process.on("exit", function (){
console.log(nb.chars +" characters");
console.log(nb.charsWithoutMentions +" characters if we do not count the mentions")
console.log(nb.mentions +" total mentions (@)");
console.log(nb.tweetsWithMention +" tweet with one mention (@) or more");
console.log(nb.tweets +" tweets");
console.log((nb.chars / nb.tweets) +" avg chars in a tweet");
console.timeEnd("delta time");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment