Created
December 14, 2017 20:13
-
-
Save chulman444/7c3e5d16c33c257651ef20c489efd80f to your computer and use it in GitHub Desktop.
Typical code for typical work. I just forget things so why not use GIST
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 json, sys | |
from functools import reduce | |
inputfilename = sys.argv[1] | |
outputfilename = sys.argv[2] | |
file = open(inputfilename, mode='r', encoding='utf-8') | |
raw = file.read() | |
file.close() | |
raw_json = json.loads(raw) | |
results = raw_json["response"]["results"] | |
words = [a["alternatives"][0]["words"] for a in results] | |
words_only = reduce(lambda a,b: a+b, words) | |
file = open(outputfilename, mode='w', encoding='utf-8') | |
file.write(json.dumps(words_only, ensure_ascii=False, indent=2)) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment