Skip to content

Commit a409ea5

Browse files
committed
Add script for migration from asciinema hosting
1 parent c485b88 commit a409ea5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/migrate_from_asciinema.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'nokogiri'
2+
require 'open-uri'
3+
4+
CASTS_IDS = [14083, 14084, 14085, 14086, 14087, 14088, 14089, 14090, 14091,
5+
14092, 14093, 14095, 14100, 14101, 14102, 14103, 14103].freeze
6+
7+
def get_cast(id)
8+
open(File.expand_path("../../source/casts/#{id}.cast", __FILE__), 'w') do |f|
9+
cast = open("https://asciinema.org/a/#{id}.cast").readlines.map do |r|
10+
# remove redundant timing precision
11+
r.gsub(/(\[\d+\.\d{2})\d+/, '\1')
12+
end.join
13+
f.puts cast
14+
end
15+
end
16+
17+
def get_poster(id)
18+
poster = Nokogiri::HTML.parse(open("https://asciinema.org/a/#{id}/embed?size=small"))
19+
.xpath('//asciinema-player')
20+
.first[:poster]
21+
open(File.expand_path("../../source/casts/#{id}.poster", __FILE__), 'w') do |f|
22+
f.puts poster
23+
end
24+
end
25+
26+
CASTS_IDS.each do |id|
27+
get_cast(id)
28+
get_poster(id)
29+
end

0 commit comments

Comments
 (0)