summaryrefslogtreecommitdiff
path: root/ast2json/strings2json.py
diff options
context:
space:
mode:
authorAlex Xu <alex_y_xu@yahoo.ca>2014-04-01 18:35:31 -0400
committerAlex Xu <alex_y_xu@yahoo.ca>2014-04-01 18:35:31 -0400
commitcfa401046d2ee1872bfbd16851f010abd837b82e (patch)
tree7c354b50acc050f92a460c4d4382d2630a372393 /ast2json/strings2json.py
parentec0e4dfd6cc67d5b948fdd0bf419866271f04b44 (diff)
downloadhtml5ks-cfa401046d2ee1872bfbd16851f010abd837b82e.tar.xz
html5ks-cfa401046d2ee1872bfbd16851f010abd837b82e.zip
stuff
Diffstat (limited to 'ast2json/strings2json.py')
-rwxr-xr-xast2json/strings2json.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/ast2json/strings2json.py b/ast2json/strings2json.py
new file mode 100755
index 0000000..0736a10
--- /dev/null
+++ b/ast2json/strings2json.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import json
+import sys
+
+def strings2json(ast):
+ ret = {}
+ if ast[0]['_type'] != 'Init': raise TypeError('obj does not start with Init, wrong file?')
+ for string in ast[0]['block'][0]['code']['ast']['body'][1:]:
+ target = string['targets'][0]
+ if target['_type'] == 'Attribute':
+ name = string['targets'][0]['attr']
+ value = string['value']
+ vtype = value['_type']
+ if vtype == 'Str':
+ ret[name] = value['s']
+ return ret
+
+with open(sys.argv[1], 'r') as f:
+ output = strings2json(json.load(f))
+
+json.dump(output, open(sys.argv[2], 'w'), separators=(',', ':'))