Created
August 31, 2010 06:14
-
-
Save jeremyBanks/558624 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3.1 | |
| import sys, collections, re, json | |
| Post = collections.namedtuple("Post", "postid _ _ username userid title _ content _ _ _ _ _ _ _ _ _ _", rename=True) | |
| raw = sys.stdin.read() | |
| raw = re.sub(r"\\(!\\)", "", raw) | |
| raw_posts = raw.replace("\r\n", "\r").split("\n") | |
| posts = [ eval("Post({})".format(raw_post.replace("\r", "\n").replace("'", "'''"))) for raw_post in raw_posts if raw_post ] | |
| json.dump([ { | |
| "username": p.username, | |
| "content": p.content, | |
| "title": p.title | |
| } for p in posts ], sys.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment