En bra gratis blogg
Lista bloggar Om Bloggis
Skapa konto Logga in

maswans bloggis

Fixing Blosxom Plugin: Twitter

Taggar: perl code regecp

A small study of regular expressions:

Found at:

http://bit-tools.googlecode.com/files/twitter022i

Is a plugin for making twitter appear on a blosxom blog. Now, there are those who thinks this is the greatest thing in the world (hi mrb!) so it is bad that it doesn't work properly.

Now this works by doing greedy regexp matching of xml elements, for instance:

$item{'pubDate'} = (/<created_at>(.*)<\/created_at>/s)[0];

This then breaks rather badly if you have mutliple created_at in the same xml entry, which you have (both for the post and for the user). The quick and dirty fix?

$item{'pubDate'} = $1 if $_ =~ /<created_at>([^<]*)<\/created_at>/s;

Instead of matching every possible character, we match everything except < which neatly confines us to one element.

While I'm at it, I also fixed some simple bugs in "addURLtags", it made some rather simplistic assumptions on which characters are allowed in URLs. In particular missing out on ~.

New version published on http://www.acc.umu.se/~maswan/blosxom/twitter.0.1-2.2i

Skrivet av maswan, 2009-04-09 21:49

twitter gillar jag inte !

Skrivet av bloggare på icedaniel.se, 2009-04-10 00:34

Kommentera:

Signatur:
Skriv här:
Vad heter Pippis författare i förnamn (stor första bokstav)?