diff options
author | Dafydd Harries <daf@rhydd.org> | 2013-03-20 21:15:04 -0400 |
---|---|---|
committer | Dafydd Harries <daf@rhydd.org> | 2013-03-20 21:15:04 -0400 |
commit | 76a7300f328b1c9bc37b371017ce45e74373d88b (patch) | |
tree | 3b9b2da7e19953f659883f3fc8c0c11ca18f2f79 | |
parent | a7b02c8875d5b26d8979c50bbfd5a81c19a9be26 (diff) |
add json_to_wiki.py script
-rw-r--r-- | export.py | 7 | ||||
-rw-r--r-- | json_to_wiki.py | 26 |
2 files changed, 31 insertions, 2 deletions
@@ -58,6 +58,9 @@ class PkgData(object): self.licenses = cp_store['licenses'] cp_store.close() +def nouni(s): + return s.encode('utf8') if isinstance(s, unicode) else s + class Template(object): def __init__(self, name, values): self.name = name @@ -65,9 +68,9 @@ class Template(object): def __str__(self): return '{{%s\n%s\n}}' % ( - self.name, + nouni(self.name), '\n'.join(['|' + '%s=%s' % - (n, v.encode('utf8') if isinstance(v, unicode) else v) + (nouni(n), nouni(v)) for (n, v) in self.values])) def parse_tags(s): diff --git a/json_to_wiki.py b/json_to_wiki.py new file mode 100644 index 0000000..b62d320 --- /dev/null +++ b/json_to_wiki.py @@ -0,0 +1,26 @@ + +import json +import sys + +import export + +def main(): + everything = json.load(sys.stdin) + + def _export(): + for (name, valuess) in everything.iteritems(): + print name + templates = [] + + for (tname, values) in valuess: + template = export.Template( + tname.decode('utf8'), values.items()) + templates.append(template) + + yield (name, templates) + + export.output_multi('converted', _export()) + +if __name__ == '__main__': + main() + |