Tag Archives: programming

PHP command line mode detection

Use a block like this in PHP code to detect whether or not it's running in command line mode as opposed to web server script mode.

// if $_ENV['SHELL'] exists, we're probably in command line mode
if (array_key_exists('SHELL', $_ENV)) {
$this->setOutputMode(MYSQLICIOUS_OUTPUT_CMD);
} else {
$this->setOutputMode(MYSQLICIOUS_OUTPUT_HTML);
}

Juice-y Python

I use Juice to manage my podcasts. But it doesn't do everything I need, and it's a little buggy, and I want to learn Python anyway. So I decided to download the latest source code and see if I could fix some of the bugs I've noticed and figure out how to extend it to do everything I need.

So step one was just getting to a point where I could compile it. The source code documentation is incomplete, so here's what I did, starting from scratch.

  1. Install Python 2.5.1
  2. Install pywin32 (I'm on Windows)
  3. Install mfc71.dll (needed by pywin32)
  4. Install py2exe (needed to compile Python source code to executable bytecode)
  5. Install wxPython (for the gui)
  6. Install pysqlite (may not be necessary, but I knew I'd need it eventually)
  7. Install NSIS (Nullsoft Scriptable Install System)
  8. Install NSIS FindProcDLL plug-in

PHEW!

Juice v.2.2.3.djm After all of that, it was actually fairly easy to build and install. However, I made the mistake of trying to upgrade the Universal Feed Parser, only to find that although Juice would still compile, install and run, it was silently crapping out while trying to read feeds so it would not actually update my podcasts. I reverted back to the version of UFP bundled with Juice and everything was fine (except for the UFP bugs I was hoping to have solved by using a later version, of course).

I should update this as things progress.

Leash and Feedparser

Maybe I'll write up something a little more formal in the future. For now, I just want to publish this in case it's useful to someone.

Les Orchard posted a blurb that indicated that he was looking for a PHP class to perform HTTP requests with conditional GET support. Well, a while ago I was looking for that, too. Because I was working on a replacement for Magpie RSS (see below), I decided to use Snoopy as my HTTP client. I then wrote a brief extension, Leash, to provide a cache-enabled front end to Snoopy. Leash automatically caches the HTTP results, the time of the request, and the Last Modified and Etag HTTP headers. When you request a page you've previously requested, Leash first checks to see if the cached copy is older than the maximum cache age you've specified (or the default of 1 hour), and if the cache is too old, Leash performs a conditional GET. The latest version of Leash (which I bundle with Snoopy) is in my Subversion repository.

Also in that repository is my replacement for Magpie RSS. I always liked Magpie, but it didn't quite work for me and I also wanted an OPML parser. So I wrote one. Actually, first I wrote a generic PHP XML parser. Then I wrote the OPML parser and Feed parser.

Sorry, but I currently don't have time for documentation. Or support. That probably makes this of very limited utility to all but the most daring. If you're a PHP junkie, you'll probably be able to peruse the code and get the gist. And here's an example of how I'm using it to help manage my podcasts.

Answer the door

Dave Winer is looking for a developer to work on Share Your OPML.

If you're interested, I strongly urge you to pick up the baton. I can vouch for what Dave says in his post: he's demanding, but he really invests in the people with whom he works. As long as you're not a prima donna who cannot handle tough questions about your work, Dave has a lot to offer as a teacher and a boss. Actually, boss is a terrible word for the working relationship you can expect to have with Dave. He's an articulate collaborator with an insight into users' wants and needs that I find amazing.

Opportunity knocks. Answer the door.

A River for NewsGator

Truly re-inspired by Dave's injection of interest into mobile news reading, I've been tinkering with my own custom solution. Since I subscribe to NewsGator, I'm using the NewsGator API for some backend, but I've done quite a bit of plumbing myself.

The most important things I wanted to be able to do were (1) to be able to mark posts read (and since I'm using NewsGator, that "read" status synchronizes across all my aggregator clients on different computers) and (2) to fix the annoying nonsense characters introduced by idiotic feed generators -- that includes the New York Times and Washington Post.

The results are starting to shape up nicely.

Here's the main page I see after I sign in.

NewsGator River screencap 01

And notice that in FeedDemon, "Chávez" is screwy, but I've got it right.

FeedDemon screen capNewsGator River screencap 02

Optimal OPML Browser Update v. 0.4

I've completed a major rewrite of my OPML browser, Optimal.

I didn't manage to document all of the changes, they were so numerous. Highlights are:

  • Object-oriented reimplementation, making it more portable to other applications
  • Same code may be used as a WordPress plugin -- replaces the OPML Renderer plugin for WordPress
  • RSS items now include descriptions, so you can browse the feeds without subscribing or visiting the home page
  • New widget generator to generate HTML to include Optimal on your web site

More... | Download