From 85e9ec60ba6275e33f3d74ec0df444e1530c2183 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 27 Jul 2015 21:29:19 -0700 Subject: [PATCH] import stuff back from pandoc --- scripts/importfrompandoc.moon | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 scripts/importfrompandoc.moon diff --git a/scripts/importfrompandoc.moon b/scripts/importfrompandoc.moon new file mode 100644 index 0000000..13b1bbb --- /dev/null +++ b/scripts/importfrompandoc.moon @@ -0,0 +1,24 @@ +sqlite3 = require "lsqlite3" + +db = assert sqlite3.open "../db/posts.db" + +update_stmt = assert db\prepare "UPDATE Posts SET mdown=? WHERE id=?" + +db\exec [[ BEGIN TRANSACTION; ]] + +for post in db\nrows "SELECT * FROM Posts" + with fout = io.open "../raw/posts/#{post.id}.textile.md", "r" + unless fout + db\exec [[ ROLLBACK; ]] + error "can't open #{post.id}.textile.md" + + body = fout\read("*a") + + do + update_stmt\bind_values body, tonumber(post.id) + update_stmt\step! + update_stmt\reset! + + fout\close! + +db\exec [[ COMMIT; ]]