The Accidental Rubyist

invalid byte sequence in UTF-8

Ruby Blogging Client for LiveJournal

leave a comment »

Following is a simple blogging client for LJ that uses curl and ruby. I took the curl portion from this Vim plugin and the documentation on the Sixapart site and the LJ site.

The curl command is simple:
curl -d @file.html
“file.html” is the name of the file containing the user, password and the content, suitably encoded.
The file the user enters in has no format. The first line is the title, and all else is the body or content. The ruby program takes this file as standard input and prints out the file that LJ will accept.It puts in the current time, and other defaults such as publish and public. Nothing fancy. It picks ip the user and password from a yaml file.

The ruby program is as follows:

#!/usr/bin/env ruby
require 'yaml'
# takes a file for LiveJournal. First line is subject. Rest is the data to be encoded.
mymap = YAML::load(;
fline = $stdin.readline.chomp!;
buff << "&mode=postevent&user="
buff << mymap["user"]
buff << ("&password=" + mymap["user1"] + "&")
fline.gsub!(' ', '+')
buff <<  "subject=%s&event=" % fline;
$stdin.each_byte { |x|
  if (x >= 65 && x <= 90) ||  (x >= 97 && x <= 122) || (x >= 48 && x <= 57) then
    buff << x
  elsif x == 32 then
    buff << "+"
    buff << "%" + ("%02x" % x)
print buff

The YAML file containing username and password is as follows:

user: johndoe
user1: zxc123

(The password put as user1 was to foil snopping siblings!)

For the moment, I issue this command:
cat 45.html | ./ljencode.rb > file.html
curl -d @file.html

The purpose of this program was essentially to send in a very large number of files from the command line, this it is not prepared for calling from Vim as yet.

However, considering the simplicity of the format, it can be used to push thoughts and musings on the fly, without requiring the content to be in some format.

I shall combine it into one ruby file and send that in the next post.

[Edited in Vim using HTML.vim]


Written by totalrecall

March 7, 2007 at 1:16 am

Posted in ruby, unix

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: