"it's like morons have invaded your screen saver!"

A while back, evan added an RSS feed that constantly spits out the most-recent public LJ posts. I just hacked up a little perl script that reads that and converts it to line-wrapped Latin1 text, after doing minimal de-HTMLification. This means you can use it as a "fortune" program with xscreensaver. For example:
    phosphor -geom =800x900 -scale 3 -delay 25000 -program './ljlatest --cols 40'

    starwars -geom =800x400 -lines 30 -steps 3 -program ./ljlatest

My understanding of Perl Unicode handling has not yet risen to the "cargo cult" level, so any improvements would be welcome (I think it should be possible to make Perl do the charset munging I did, but I couldn't figure out how.)

Tags: , , ,

27 Responses:

    • Did you build XScreensaver by hand, or did you install RH's package for it?

      'cause, uh, /usr/games doesn't exist under any Linux distro (it's a BSD thing). And it's very easy to change the fortune path, at least at compile-time.

      • eru says:

        It exists under Debian.

        man 7 hier:
        Binaries for games and educational programs (optional).

        ls /usr/games:
        banner fortune robotfindskitten

      • waider says:

        It's actually in /usr/share/games on newer Red Hats (fsstd or whatever), but that's neither here nor there. As of Red Hat 9 they're no longer shipping fortune due to "unclear copyright status".

      • suppafly says:

        don't most distro's give you the option to install the bsdgames? i've seen the option on most that i've installed.

  1. saintnobody says:

    quoth the perlunicode(1) man page from v5.6.1:

    As of yet, there is no method for automatically coercing input and output to some encoding other than UTF-8. This is planned in the near future, however.

    so it seems that, while you can read it in as unicode, you can't force it to output as latin1. iirc, the character encoding support is much better in perl 5.8, but i don't think that has wide enough adoption to require it.

    • brad says:

      The perl core doesn't support it, but there are Perl modules to do it. We do it on LiveJournal with Unicode::MapUTF8 which can go to/from UTF-8 and any other charset.

      • saintnobody says:

        true. there's a perl module for damn near everything conceivable. but requiring a perl module for things to work has its own problems. as it is, his solution is kind of a hack, but at least it works without anybody having to download a module or install a new version of perl.

  2. ivorjawa says:

    Python has nice unicode support, and a decent XML parser "out of the box", making it very useful for this kind of web services work. I'll see if I can hack something together if I ever stop sneezing today.

  3. brianenigma says:

    Wow, that's funny--I posted Java code a couple of days ago to do something similar. (I had a version in Perl a while back, but it was the worst Perl hack ever, considering I suck with the language.) The Java code uses the "find random user" function in LJ along with another function to force an entry to be viewed in a particular style (for easy parsing) instead of the recent posts feed, but I use it for the same sort of thing (the starwars screensaver on my Freevo box hooked to a big TV).

    Now, if we could just hack the LJ code to return a random entry as an RSS feed...

  4. nerpdawg says:

    The script is wonderful, but now that I can see the latest lj posts, oi..

  5. node says:

    30 seconds isn't enough to download the rss file over 33.6k dialup. 60 seconds appears to work fine.

  6. earle says:

    (Reposted without the formatting that messed up the table in your comments page. Sorry.)

    You're doing...

    my %entity_table = (
    "quot" => '"', "amp" => '&', "lt" => '<', "gt" => '>',
    "nbsp" => ' ', "iexcl" => '¡', "cent" => '¢', "pound" => '£',

    ...and so on.

    This is reinventing a wheel; no need. Use HTML::Entities and save yourself a whole lot of pain.

    > My understanding of Perl Unicode handling has not
    > yet risen to the "cargo cult" level

    Try something like Unicode::Lite.

    • gwillen says:

      Use HTML::Entities
      something like Unicode::Lite

      Are these things that come with Perl, and are thus useful in a program meant to be distributed; or are they in the CPAN abomination?