Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created August 31, 2010 06:14
Show Gist options
  • Select an option

  • Save jeremyBanks/558624 to your computer and use it in GitHub Desktop.

Select an option

Save jeremyBanks/558624 to your computer and use it in GitHub Desktop.
#!/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