Skip to content

Instantly share code, notes, and snippets.

@danieltamiosso
Created July 28, 2010 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save danieltamiosso/494525 to your computer and use it in GitHub Desktop.
Save danieltamiosso/494525 to your computer and use it in GitHub Desktop.
Plugin to Wind for Wordpress importer
#
# Wind Wordpress Importer
#
# To install this plugin do you need copy the file to Wind plugins directory.
# An admin widget will be crated to import WordPress eXtended RSS file.
#
# This plugin use hurricane gem [http://github.com/danieltamiosso/hurricane],
# [gem install hurricane] to install it.
#
require 'hurricane'
at_start do
if not Widget[:title => 'Wordpress Importer']
widget = Widget.new
widget.title = 'Wordpress Importer'
widget.content = '<form method="post" action="wordpress-importer" enctype="multipart/form-data"><input type="file" name="wordpress_file" placeholder="Wordpress file to import..."/><button type="submit">Go</button></form>'
widget.admin = true
widget.order = 1000
widget.save
end
end
post '/wordpress-importer' do
if_logged do
to_wind params[:wordpress_file][:tempfile]
end
go_home
end
def to_wind(file)
blog = Hurricane::Parse.from(file)
$settings.name = blog.title
$settings.title = blog.description
$settings.save
blog.posts.each do |imported_post|
post = Post.new
post.title = imported_post.title
post.text = imported_post.description
post.date = imported_post.created_at
post.link = imported_post.link.split('/')[-1]
post.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment