Skip to content

Instantly share code, notes, and snippets.

@ku1ik
Last active February 26, 2018 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ku1ik/934ac2148c1f5aa80fba4d983e646f67 to your computer and use it in GitHub Desktop.
Save ku1ik/934ac2148c1f5aa80fba4d983e646f67 to your computer and use it in GitHub Desktop.
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