Skip to content

Instantly share code, notes, and snippets.

@sickill

sickill/edit-asciicast.py

Last active Feb 26, 2018
Embed
What would you like to do?
import sys
import os
import json
import asciinema.asciicast as asciicast
import asciinema.asciicast.frames as frames
# run me with:
# python3 edit-asciicast.py original.cast edited.cast
def write_json_line(f, value):
line = json.dumps(value, ensure_ascii=False, indent=None, separators=(', ', ': '))
f.write(line + '\n')
with asciicast.open_from_url(sys.argv[1]) as cast:
stdout = cast.stdout()
stdout = frames.to_relative_time(stdout)
header = {
'version': 2,
'width': 80, # cast.width,
'height': 24 # cast.height
}
with open("/tmp/foo.cast", mode='w') as f:
write_json_line(f, header)
for t, text in stdout:
write_json_line(f, [t, "o", text])
os.system("vim /tmp/foo.cast")
with asciicast.open_from_url("/tmp/foo.cast") as cast:
stdout = cast.stdout()
stdout = frames.to_absolute_time(stdout)
header = {
'version': 2,
'width': 80, # cast.width,
'height': 24 # cast.height
}
with open(sys.argv[2], mode='w') as f:
write_json_line(f, header)
for t, text in stdout:
write_json_line(f, [t, "o", text])
os.unlink("/tmp/foo.cast")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment