From 0fe8fbfc6aea4b566486b01dfb469125df30c8c5 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 19 Nov 2012 00:20:32 +0100 Subject: [PATCH] Script for fetching asciicast from http://ascii.io to local filesystem --- script/fetch.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 script/fetch.rb diff --git a/script/fetch.rb b/script/fetch.rb new file mode 100755 index 0000000..a6c3311 --- /dev/null +++ b/script/fetch.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +require 'open-uri' +require 'json' +require 'fileutils' +require 'base64' + +id = ARGV[0] + +id = id[/\d+/].to_i + +url = "http://ascii.io/a/#{id}.json" + +json = open(url).read +data = JSON.parse(json) + +dir = "tmp/fetched/#{id}" +FileUtils.mkdir_p(dir) +Dir.chdir(dir) + +File.open('stdout', 'wb') do |f| + stdout_data = Base64.decode64(data['escaped_stdout_data']) + f.write stdout_data +end + +File.open('stdout.time', 'w') do |f| + data['stdout_timing_data'].each do |line| + f.puts line.join(' ') + end +end + +system "bzip2 stdout.time && mv stdout.time.bz2 stdout.time" + +File.open('meta.json', 'w') do |f| + json = { + :duration => data['duration'], + :term => { + :columns => data['terminal_columns'], + :lines => data['terminal_lines'] + } + } + + f.write JSON.dump(json) +end