Archiving Twitter to Blog Post

Submitted by tomo on October 5, 2012 - 10:30am

Step 1: Install t (Ruby Twitter command line client). Run the following (substitute your own Twitter ID):

t timeline @tomosaigon --csv --number 3000 > tweets.csv

Step 2: Convert CSV to JSON using http://www.cparker15.com/wp-content/uploads/csv-to-json/csv-to-json.html

Step pre-3:

cached=$(/usr/bin/grep $1 $CACHE)
if [[ $cached != "" ]]; then
        echo $cached|/usr/bin/cut -d' ' -f2 ; 
        exit
fi
 
url=$(/usr/local/bin/curl -v $1 2>&1|/usr/bin/grep '^< Location: '|/usr/bin/sed -e 's/< Location: //')
echo $1 $url >> $CACHE
echo $url

Step 3: Open Chrome Developer Tools and in the command line type "var a = " then paste the copied JSON. Hit enter.

var out = '';
for (var i = 0; i < a.length; i++) {
    var t = a[i]; 
    var d = new Date(t['Posted at']); 
    if (d >= new Date('2012-09-01 00:00') && d <= new Date('2012-10-01 00:00')) {
        var tweet = t['Text'];
        var tcos = tweet.match(/http:\/\/t.co\/\w+/g);
        if (tcos) {
            for (var m = 0; m < tcos.length; m++) {
                tco = tcos[m].replace(/\//g, '%252F');
                $.ajax({url:'http://www.saigonist.com/saigonist/untco/' + tco, async:false, success:function(data){
                    tweet = tweet.replace(tcos[m], data.trim());
                }});
            }
        }
 
        tweet = tweet.replace(/("")/g, '"').replace(/(^|\s)@(\w+)/g, '\$1<a href="https://twitter.com/\$2" rel="nofollow">@\$2</a>').replace(/(^|\s)#(\w+)/g, '\$1<a href="https://twitter.com/#!/search/%23\$2" rel="nofollow">\$2</a>')
        out += ((d.getMonth() + 1) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ' ' + tweet + ' ' + '<a href="http://twitter.com/' + t['Screen name'] + '/statuses/' + t['ID'] + '" rel="nofollow">#</a>');
        out += '\n';
    }
}

© 2010-2014 Saigonist.