Posted by rick
Sat, 11 Feb 2006 06:07:00 GMT
Note to self…
- calendar(s), schedule, etc. need to stay w/ backend.rickbradley.com, or something similar
- /rss/ page should list feeds, /rss/ should provide individual feeds
- backend should do stats/; lock down /stats/
- ping -> post functionality
- put in a 404 handler that talks about the move, and logs to a file when there are problems
- go through old directories and make sure nothing has been left out.
- look at optimizing Typo’s unbelievably slow-ass “archives” sidebar query so I can actually use it.
Tags site | no comments
Posted by rick
Sat, 11 Feb 2006 04:45:00 GMT
For years and years I’ve used a perl script to convert inbound emails to my site to posts on the site (that technique has probably been patented by some asshat within the past year—such being the USPTO & the Internet). I was using a flat-file archive of my own creation which was dead simple and geared towards mostly “link log” type posts. The front-end was a PHP engine I wrote (also years and years ago) which would simply spray those flat-filed posts to the page on demand.
Now that I’m almost switched over to Ruby on Rails and Typo I needed to update the tool which receives email and makes posts from it. Here’s the Ruby code to do it:
#!/usr/local/bin/ruby
require File.dirname(__FILE__) + '/../config/boot'
require File.dirname(__FILE__) + '/../config/environment'
#
# process an email, extract link data and create a Typo post with tags
#
# TODO: care about someone other than me using this
# (grep for /[Rr]ick/ below...)
class InboundMailer < ActionMailer::Base
def initialize
@tags = {}
end
def receive(mail)
# extract the subject, split into tag words
tags = mail.subject.split(/\s+/)
# extract the relevant body fragment(s)
body = mail.body.split("\n")
buffer = []
body.each do |line|
break if line =~ /^(?:\s*-+)|Rick/ # when is the mail finished?
if line =~ /^\s*$/ # whitespace separates posts
article = create_article(buffer)
set_article_tags(article, tags)
buffer = []
else
buffer << line
end
end
end
# given a set of lines comprising a post, turn this
# into an Article, returning the Article
def create_article(lines)
title = lines.shift
Article.create :title => title, :body => lines.join("\n"),
:author => 'rick', :user_id => 1, :allow_comments => true,
:text_filter_id => 5
end
# associate an Article with a set of Tag instances
def set_article_tags(article, tags)
tags.each do |t|
unless @tags[t]
begin Tag.create :name => t, :display_name => t rescue nil; end
@tags[t] = true
end
my_tag = Tag.find(:first, :conditions => ['name = ?', t])
article.tags << my_tag
end
end
end
# process the email
InboundMailer.receive(STDIN.readlines.join(''))
Yeah, there's a little bit of the old hardwiring there. Feel free to unwire for your own needs.
Tags output, site | no comments
Posted by rick
Tue, 07 Feb 2006 16:16:00 GMT
I’m in the midst of converting this site over from the home-grown PHP engine that has served so well for years to a Typo installation, with various grafted on bits of Ruby on Rails to tie the bits and pieces together.
The data conversion from my custom flat-file datastore was almost trivial: it took ~13 minutes to convert some 5000 posts, and the script was just:
require File.dirname(__FILE__) + '/../config/boot'
require File.dirname(__FILE__) + '/../config/environment'
exclude = {}
# convert rickbradley.com entries into typo weblog posts
ARGV.each do |filename|
STDERR.puts "new file [#{filename}]"
tag = File.basename(filename).gsub(/\.\d+$/, '')
next if exclude[tag]
File.open(filename) do |file|
# create the tags entry for this file
begin Tag.create :name => tag, :display_name => tag rescue nil; end
my_tag = Tag.find(:first, :conditions => ['name = ?', tag])
file.readlines.each do |line|
timestamp, url, title, body = line.split /#%#/
title.chomp!
(body ||= '').chomp!
url.sub!(/^\//, 'http://www.rickbradley.com/')
body = %Q{<a href="#{url}">#{title}</a>} + (body != '' ? " - #{body}" : '')
datetime = Time.parse(timestamp)
puts "[#{timestamp}]->[#{datetime}] [#{title}] [#{body}] [#{tag}]"
# create a post from this data
article = Article.create :title => title, :body_html => body,
:author => 'rick', :created_at => datetime,
:updated_at => datetime, :user_id => 1
# link the post and its tags
article.tags << my_tag
end
end
end
(and most of that was just dealing with the silly one-line-per-post flat file format I hacked up in 5 minutes 5 years ago).
Things left to do (this list is for me as much as anyone):
- convert over my handful of notes posts
- bring over static pages
- change the “theme”
- update the mail -> post procmail handler
- put all the hidden stuff (images, etc.) into the public/ subdirectory for rails
- alias the old link scheme via RoR routes
- look at optimizing the unbelievably slow-ass “archives” sidebar query so I can actually use it.
Then, the point of all this nonsense (other than getting out from under PHP) is that I’ll make a minor hack to the ‘ping’ functionality for posts on this site and a handful of others, so that any post on the other sites ends up creating a mirrored post on this site, with appropriate categories and/or tags.
Tags output, site | no comments | no trackbacks