Skip to content

Instantly share code, notes, and snippets.

@urialon
Created April 20, 2020 10:49
Show Gist options
  • Save urialon/6ce2ffab7b675d9437b730246dc07827 to your computer and use it in GitHub Desktop.
Save urialon/6ce2ffab7b675d9437b730246dc07827 to your computer and use it in GitHub Desktop.
from argparse import ArgumentParser
import os
import json
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument("-in", "--input", dest="input_file",
help="path to input file", required=True)
parser.add_argument("-out", "--output", dest="output_dir", required=True)
args = parser.parse_args()
#os.mkdir(args.output_dir)
with open(args.input_file, 'r') as infile:
with open('%s/align.txt' % (args.output_dir), 'w') as align_file:
for i,line in enumerate(infile.readlines()):
line = line.strip()
obj = json.loads(line)
target = obj['nl']
code = obj['code']
with open('%s/example_%d.java' % (args.output_dir, i), 'w') as outfile:
outfile.write('class A {\n%s}\n' % code)
align_file.write('example_%d.java %s\n' % (i, target))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment