Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created Apr 30, 2012
Embed
What would you like to do?
var Canvas = require('canvas'),
_ = require('underscore'),
fs = require('fs');
var w = 800,
h = 500;
var c = new Canvas(w, h);
var ctx = c.getContext('2d');
ctx.fillStyle = '#fff';
ctx.fillRect(0, 0, w, h);
ctx.fillStyle = '#000';
ctx.font = '28pt Helvetica';
ctx.globalAlpha = 0.01;
var linewidth = 13;
var lineheight = 50;
var f = fs.readFileSync('itunes.csv', 'utf8');
var lines = f.split(/\n/).slice(1).map(function(l) {
var lines = '';
var name = l.split(',')[1];
if (name) {
var words = name.split(/\s+/);
var line = '';
var level = 50;
for (var i = 0; i < words.length; i++) {
if (line.length > linewidth) {
ctx.fillText(line, 10, level);
line = '';
level += lineheight;
}
line += words[i] + ' ';
}
if (line) {
ctx.fillText(line, 10, level);
}
}
});
fs.writeFileSync('names.png', c.toBuffer());
require 'osx/cocoa'
require 'rubygems'
require 'fastercsv'
FasterCSV.open("itunes.csv", "w") do |csv|
csv << ['artist', 'name', 'plays', 'totaltime']
OSX.load_plist(File.read(ARGV[0]))['Tracks'].each do |id, info|
csv << [info['Artist'], info['Name'], info['Play Count'], info['Total Time']]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment