Skip to content

Instantly share code, notes, and snippets.

@dchaplinsky
Created October 23, 2014 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchaplinsky/25b7ae950cbac4e39e70 to your computer and use it in GitHub Desktop.
Save dchaplinsky/25b7ae950cbac4e39e70 to your computer and use it in GitHub Desktop.
import MySQLdb
import json
import html2text
con = MySQLdb.connect('localhost', 'root', '', 'nashig', use_unicode=True)
with con:
h = html2text.HTML2Text()
h.ignore_links = True
cur = con.cursor()
cur.execute("SELECT post_title, post_content from wp_posts")
with open("lines.json", "w") as fp:
for title, content in cur.fetchall():
fp.write(json.dumps({
"title": h.handle(title).strip(),
"content": h.handle(content).strip()
}) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment