Last active
February 26, 2018 22:13
-
-
Save ku1ik/934ac2148c1f5aa80fba4d983e646f67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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