Sha256: 5ac910b0319dc038f7c70552c3d1549e08da2b3999ee9df9188d2911c964be3c

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

module Storytime
  module Importers
    class Wordpress < Importer
      attr_accessor :xml

      def import!
        self.xml = Nokogiri::XML(file_content)
        posts = []

        self.xml.xpath("//item").each do |item|
          if item.xpath(".//wp:post_type[contains(., 'post')]").length > 0
            post = Storytime::BlogPost.new
            post.title = item.xpath("title").text
            post.user = creator
            post.content = item.xpath("content:encoded").text
            post.draft_content = post.content
            
            date = item.xpath("wp:post_date_gmt").text
            if date && !date.blank? && date != "0000-00-00 00:00:00"
              post.created_at = Time.strptime(date+" UTC", "%Y-%m-%d %H:%M:%S %Z")
            end

            if item.xpath("wp:status").text == "publish"
              pub_date = item.xpath("pubDate").text
              if pub_date && !pub_date.blank?
                post.published_at = Time.strptime(pub_date, "%a, %d %b %Y %H:%M:%S %z")
              end
            end

            post.save
            posts << post
          end
        end

        posts
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
storytime-2.1.6 lib/storytime/importers/wordpress.rb
storytime-2.1.5 lib/storytime/importers/wordpress.rb
storytime-2.1.4 lib/storytime/importers/wordpress.rb
storytime-2.1.3 lib/storytime/importers/wordpress.rb
storytime-2.1.2 lib/storytime/importers/wordpress.rb
storytime-2.1.1 lib/storytime/importers/wordpress.rb
storytime-2.1.0 lib/storytime/importers/wordpress.rb
storytime-2.0.0 lib/storytime/importers/wordpress.rb
storytime-1.2.0 lib/storytime/importers/wordpress.rb
storytime-1.1.1 lib/storytime/importers/wordpress.rb
storytime-1.0.7 lib/storytime/importers/wordpress.rb
storytime-1.0.6 lib/storytime/importers/wordpress.rb
storytime-1.0.5 lib/storytime/importers/wordpress.rb
storytime-1.0.2 lib/storytime/importers/wordpress.rb
storytime-1.0.1 lib/storytime/importers/wordpress.rb
storytime-1.0.0 lib/storytime/importers/wordpress.rb
storytime-0.0.4 lib/storytime/importers/wordpress.rb