{"action":"created","issue":{"url":"https://api.github.com/repos/atbyrd/blog/issues/1","repository_url":"https://api.github.com/repos/atbyrd/blog","labels_url":"https://api.github.com/repos/atbyrd/blog/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/atbyrd/blog/issues/1/comments","events_url":"https://api.github.com/repos/atbyrd/blog/issues/1/events","html_url":"https://github.com/atbyrd/blog/issues/1","id":137043274,"number":1,"title":"Blog import","user":{"login":"PascalPencil","id":3094044,"avatar_url":"https://avatars.githubusercontent.com/u/3094044?v=3","gravatar_id":"","url":"https://api.github.com/users/PascalPencil","html_url":"https://github.com/PascalPencil","followers_url":"https://api.github.com/users/PascalPencil/followers","following_url":"https://api.github.com/users/PascalPencil/following{/other_user}","gists_url":"https://api.github.com/users/PascalPencil/gists{/gist_id}","starred_url":"https://api.github.com/users/PascalPencil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PascalPencil/subscriptions","organizations_url":"https://api.github.com/users/PascalPencil/orgs","repos_url":"https://api.github.com/users/PascalPencil/repos","events_url":"https://api.github.com/users/PascalPencil/events{/privacy}","received_events_url":"https://api.github.com/users/PascalPencil/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-28T11:44:41Z","updated_at":"2016-03-18T08:16:31Z","closed_at":"2016-03-18T08:16:31Z","body":"https://github.com/atbyrd/blog/blob/master/lib/tasks/import_wordpress.rake#L30\r\n\r\nThe script downloads and processes all images but doesn't actually seem to make the images in the post body point to the newly generated images, they point to their old urls?"},"comment":{"url":"https://api.github.com/repos/atbyrd/blog/issues/comments/198247800","html_url":"https://github.com/atbyrd/blog/issues/1#issuecomment-198247800","issue_url":"https://api.github.com/repos/atbyrd/blog/issues/1","id":198247800,"user":{"login":"PascalPencil","id":3094044,"avatar_url":"https://avatars.githubusercontent.com/u/3094044?v=3","gravatar_id":"","url":"https://api.github.com/users/PascalPencil","html_url":"https://github.com/PascalPencil","followers_url":"https://api.github.com/users/PascalPencil/followers","following_url":"https://api.github.com/users/PascalPencil/following{/other_user}","gists_url":"https://api.github.com/users/PascalPencil/gists{/gist_id}","starred_url":"https://api.github.com/users/PascalPencil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PascalPencil/subscriptions","organizations_url":"https://api.github.com/users/PascalPencil/orgs","repos_url":"https://api.github.com/users/PascalPencil/repos","events_url":"https://api.github.com/users/PascalPencil/events{/privacy}","received_events_url":"https://api.github.com/users/PascalPencil/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T08:16:31Z","updated_at":"2016-03-18T08:16:31Z","body":"Hi! We fixed it, the following code changes the links to the images inside of the article.body (post.body for you) after importing them :) :100: \r\n\r\n```ruby\r\nrequire 'action_view'\r\nrequire 'nokogiri'\r\n\r\nnamespace :wordpress do\r\n  desc 'Import Worpress Posts'\r\n\r\n  task import_posts: :environment do |_, _args|\r\n    Bootsy::ImageGallery.destroy_all\r\n    Bootsy::Image.destroy_all\r\n    Article.destroy_all\r\n    counters = {articles: 0, images: 0, bootsy_image: 0}\r\n    errors = []\r\n    File.open('lib/post.xml') do |file|\r\n      items = Nokogiri::XML(file).xpath('//channel//item')\r\n      items.first(3).each do |item|\r\n        begin\r\n          counters[:articles] += 1\r\n          article = Article.create(\r\n            title: item.at_xpath('title').text.strip,\r\n            shorthand: item.at_xpath('wp:post_name').text.strip,\r\n            body: item.at_xpath('content:encoded').text,\r\n            bootsy_image_gallery: Bootsy::ImageGallery.create\r\n          )\r\n          article.save(validate: false)\r\n          article.update_column(:created_at, item.at_xpath('wp:post_date_gmt').text)\r\n          images = item.at_xpath('content:encoded').text.scan(/\"([a-z\\-_0-9\\/\\:\\.]*\\.(jpg|jpeg|png|gif))\"/i)\r\n          if images.any?\r\n            amount_of_images = 0\r\n            images.each do |image|\r\n              counters[:images] += 1\r\n              bootsy_image = Bootsy::Image.new(remote_image_file_url: image.first.sub(/^http:/, 'https:'), image_gallery: article.bootsy_image_gallery)\r\n              if bootsy_image.valid?\r\n                article.bootsy_image_gallery.images << bootsy_image\r\n                article.update_column(:body, article.body.gsub(image.first, article.bootsy_image_gallery.images[amount_of_images].image_file.large.url).gsub(image.first.sub(/^http:/, 'https:'), article.bootsy_image_gallery.images[amount_of_images].image_file.large.url).gsub(image.first.sub(/^https:/, 'http:'), article.bootsy_image_gallery.images[amount_of_images].image_file.large.url))\r\n                article.save(validate: false)\r\n                counters[:bootsy_image] += 1\r\n                amount_of_images += 1\r\n              else\r\n                errors << \"article #{article.id}, bootsy_image failed; #{bootsy_image.errors.full_messages.join('. ')}\"\r\n              end\r\n            end\r\n            article.save\r\n          end\r\n        rescue StandardError => e\r\n          puts \"#{e}\"\r\n          next\r\n        end\r\n      end\r\n    end\r\n    puts \"Status:\"\r\n    counters.each_pair { |k, v| puts \"#{k}: #{v}\"}\r\n    if errors.present?\r\n      puts \"Errors: #{errors.count}\"\r\n      errors.each { |e| puts e }\r\n    end\r\n  end\r\nend\r\n```"}}