Last active
April 21, 2020 13:29
-
-
Save jrun/34460f8d0fcb105898359563335e533f to your computer and use it in GitHub Desktop.
Quick and dirty script to merge asciicast files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'json' | |
require 'pathname' | |
cast_files = ARGV.map { |cast| Pathname cast } | |
# | |
# Merge files | |
# | |
master_cast = cast_files.shift.readlines.map { |line| JSON.parse line } | |
cast_files.each do |cast| | |
last_time = Float master_cast.last.first | |
cast.readlines[1..-1].each do |line| | |
new_line = JSON.parse(line) | |
# | |
# Adjust time | |
# | |
new_line[0] = Float(new_line.first) + last_time | |
master_cast << new_line | |
end | |
end | |
puts master_cast.map { |line| JSON.dump line }.join("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment