summaryrefslogtreecommitdiffstats
path: root/posts/import-drupal.lua
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2014-10-01 22:11:18 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2014-10-01 22:27:42 +0200
commitd857e13f7a8b3d5c938eaaeb005898b7a631233a (patch)
tree584adf2dd31d2151b8e9d1ee9957b4812f75260f /posts/import-drupal.lua
parent95a011b0d729d4a31dd20d81b409417ac671a6ce (diff)
downloadalpine-mksite-d857e13f7a8b3d5c938eaaeb005898b7a631233a.tar.bz2
alpine-mksite-d857e13f7a8b3d5c938eaaeb005898b7a631233a.tar.xz
initial import of news posts
Diffstat (limited to 'posts/import-drupal.lua')
-rw-r--r--posts/import-drupal.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/posts/import-drupal.lua b/posts/import-drupal.lua
new file mode 100644
index 0000000..5db259a
--- /dev/null
+++ b/posts/import-drupal.lua
@@ -0,0 +1,42 @@
+
+env = require('luasql.mysql').mysql()
+
+con = assert(env:connect("alpine-www-backup", 'www-backup', 'sYUsThNBGnPR6fmy', '192.168.122.13'))
+
+print (con)
+cur = assert(con:execute([[
+
+select
+ r.title as title,
+ r.timestamp as timestamp,
+ b.body_value as body
+from
+ node_revision r,
+ node n,
+ field_revision_body b
+where
+ n.vid=r.vid and n.type='news' and r.status=1 and r.vid=b.revision_id;
+
+]]))
+
+row = cur:fetch ({}, "a")
+while row do
+ local fn = "posts/"..row.title:gsub("[ :]", "-")..".md"
+ local f = io.open(fn, "w")
+ f:write(("---\n"..
+ "title: '%s'\n"..
+ "date: %s\n"..
+ "---\n"..
+ "\n# %s\n"):format(row.title,
+ os.date("%Y-%m-%d", tonumber(row.timestamp)),
+ row.title))
+ f:write(row.body)
+ f:close()
+-- io.write(row.body)
+ row = cur:fetch ({}, "a")
+end
+
+cur:close()
+con:close()
+env:close()
+