summaryrefslogtreecommitdiffstats
path: root/posts/import-drupal.lua
blob: 5db259acd106d2bf5b60552f5eeb80646c98ba49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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()