Browse files

Grabs Quote text during import

  • Loading branch information...
1 parent 51a8c2c commit 62a2be388e899abc5bf3e08f5548a05417a0cc2f @pengwynn pengwynn committed Nov 5, 2011
Showing with 17 additions and 13 deletions.
  1. +17 −13 lib/thimblr/importer.rb
View
30 lib/thimblr/importer.rb
@@ -12,10 +12,10 @@ def self.username(username)
rescue OpenURI::HTTPError
raise "Username not found"
end
-
+
data['Title'] = xml.search('tumblelog')[0]['title']
data['Description'] = xml.search('tumblelog')[0].content
-
+
data['Posts'] = []
xml.search('posts post').each do |xpost|
post = {
@@ -25,20 +25,21 @@ def self.username(username)
'Timestamp' => xpost['unix-timestamp'].to_i,
'Tags' => xpost.search('tag').collect{ |tag| tag.content }
}
-
+
post['Type'] = "Text" if post['Type'] == "Regular"
post['Type'] = "Chat" if post['Type'] == "Conversation"
-
+
post.store('Title', xpost.search("#{xpost['type']}-title")[0].content) rescue nil
-
+
post.store('Caption',xpost.search("#{xpost['type']}-caption")[0].content) rescue nil
-
+
post.store('LinkURL',xpost.search("#{xpost['type']}-link-url")[0].content) rescue nil
post.store('Source',xpost.search("#{xpost['type']}-source")[0].content) rescue nil
-
+
post.store('Description',xpost.search("#{xpost['type']}-description")[0].content) rescue nil
-
+
+
case post['Type']
when "Photo"
xpost.search('photo-url').each do |photo|
@@ -49,20 +50,23 @@ def self.username(username)
post['Name'] = xpost.search("link-text")[0].content
rescue
end
+ when "Quote"
+ puts xpost.search("quote-text").inspect
+ post['Quote'] = xpost.search("quote-text")[0].content
when "Video"
post['Player'] = xpost.search("video-player")[0].content
when "Text"
post['Body'] = xpost.search("regular-body")[0].content
end
-
+
data['Posts'].push post
end
-
+
# Pages
begin
xml = Nokogiri::XML(open("http://#{username}.tumblr.com/api/pages"))
data['Pages'] = []
-
+
xml.search('pages').children.each do |re|
case re.name
when "redirect"
@@ -84,8 +88,8 @@ def self.username(username)
rescue OpenURI::HTTPError
# No pages
end
-
+
YAML::dump(data)
end
end
-end
+end

0 comments on commit 62a2be3

Please sign in to comment.