The Accidental Rubyist

invalid byte sequence in UTF-8

Archive for the ‘blogging’ Category

Simple Drupal Blog Poster (ruby xmlrpc)

leave a comment »

After yesterday’s struggle getting ruby 1.8.5 to do a post with drupal, today i quickly put together a simple drupal poster. It posts a new post, and can update the same.
Its a Simple poster in the sense that it takes a file in the following minimal format:
first line is subject
rest is content.
In the case of editing (updating a post), first line must be POSTID: <postid>.
That’s it — no categories etc.

For a full-fledged drupal/MT poster, please use mtsend.py. If you are having problems with ruby and drupal, pls see the previous post. A minor change or 2 is required in the xmlrpc/client.rb. I am posting to an old version of drupal, perhaps the new versions correctly return Content-Type as “text/xml, and not html.
DOWNLOAD drupalpost.rb.
~~~
“If you want to travel around the world and be invited to speak at a lot
of different places, just write a Unix operating system.”
(By Linus Torvalds)

Written by totalrecall

March 19, 2007 at 12:44 am

Posted in blogging, ruby

Power Blogging from Unix (and Vim)

leave a comment »

The benefit of using a unix shell (Unix/Linux/Mac OS X) for blogging is not just that one can use one’s favorite editor, such as Vim, or even something absolutely freakingly great such as html.vim, but also …

One painful part of blogging can be creating hyperlinks. There are links in your browser bookmark file, and links in your previous blogs sitting on your system, why not use these automatically. OK, we don’t expect that fancy, shiny GUI blogging system to really work up so much sweat. But a few lines of your favorite scripting language, a.k.a ruby, can easily do some amount of hyperlinking for you.

So i have touched up 3 scripts i wrote while trying out Ecto :
1. inter.rb runs first on the body of this post. it interchanges all Drupal interwiki style formatting into links to wikipedia, google etc.
2. urlize.rb runs next on the BODY, replacing all single bracket tags with whats in my URL file, created from posts i have already sent.
3. Finally, urlize.rb takes care of any words in its list, that it finds in the post (delimited with space before and a space or comma or period after.
4. If i wish to search my bookmarks for a specific URL, F5 invokes searchbookmarks.sh which takes a word/phrase, searches the bookmarks file and presents me with a list. I can select one, and the URL is placed in clipboard, ready to paste in.

The URL files used by the ruby scripts are in YAML format, created by a simple one-liner on my bash shell.

Some programs allow one to get to the frontmost URL of safari (standard browser on MAC). That’s lame, really. What with multiple windows and tabs. And what of closed tabs, and my history?

The above scripts are all in files folder. I guess as i keep blogging from Vim, more will come out. I am posting this to WordPress using mtsend.py AND to Blogger using blogger.sh (which speaks the Moveable Type format pretty fluently.

The command to do the magic linking (in .vimrc) is:
nmap \l :/BODY:/,$ ! inter.rb <bar> urlify.rb <bar> urlize.rb
(that’s a “forward-slash l” in case the blog lops it off)

My apologies to any mouse-warriors and GUI-masochists reading this post.
(All links above were automatically created!)

A command like the following can be used to create the YAML file from your posts (apologies for poor scripting)

Read the rest of this entry »

Written by totalrecall

March 15, 2007 at 12:33 am

Posted in blogging, ruby, unix