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
43
44
45
46
47
48
49
50
51
|
# File 'lib/blogr/import.rb', line 10
def self.wordpress(path)
if File.exist?(path)
f = File.open(path)
data = XmlSimple.xml_in(f.read)
blog_title = data['channel'][0]["title"][0]
blog_link = data['channel'][0]["link"][0]
data['channel'][0]["category"].each do |c|
Blogr::Category.create title: c["cat_name"][0]
end
data['channel'][0]["item"].each do |p|
pub = p["status"][0] == "publish" ? true : false
is_post = p["post_type"][0] == "post" ? true : false
permalink = p["post_name"][0]
content = ReverseMarkdown.parse(p["encoded"][0])
if is_post
post = Blogr::Post.create title: p["title"][0], content: content, permalink: permalink, published: pub, published_at: p["pubDate"][0]
p["category"].each do |c|
post.tags.create name: c["content"]
end
puts "> Imported post - #{post.title}"
end
end
puts "Import Complete"
else
raise ImportError, "The Blogr importer couldn't file the file at #{path}"
end
end
|