Created
June 6, 2017 14:47
-
-
Save jmaupetit/368fb9f93d15afcd74e2598c6bffed99 to your computer and use it in GitHub Desktop.
Fix TailorDev Watson uuids in frames
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 python3 | |
""" | |
Use this script if you have corrupted frames in your watson history. In my | |
case, almost 400 frames had short ids instead of 32 chars uuids. | |
Usage: | |
$ cd path/to/watson/dir | |
$ wget GIST_URL -O fix_watson_uuids.py | |
$ python3 fix_watson_uuids.py | |
$ cp frames frames.bkp | |
$ mv frames.fix frames | |
""" | |
import json | |
import uuid | |
def load_frames(): | |
with open('frames') as f: | |
return json.load(f) | |
def fix_uuids(frames): | |
fixed_frames = [] | |
for frame in frames: | |
if len(frame[3]) != 32: | |
frame[3] = uuid.uuid4().hex | |
fixed_frames.append(frame) | |
return fixed_frames | |
def save_frames(frames): | |
with open('frames.fix', 'w') as f: | |
json.dump(frames, f, indent=1, ensure_ascii=False) | |
def main(): | |
frames = load_frames() | |
frames = fix_uuids(frames) | |
save_frames(frames) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment