...making Linux just a little more fun!

next -->

The Mailbag

HELP WANTED : Article Ideas
Submit comments about articles, or articles themselves (after reading our guidelines) to The Editors of Linux Gazette, and technical answers and tips about Linux to The Answer Gang.

Python, tail -f, pyurlview, non-blocking I/O

Mon, 28 Mar 2005 05:03:50 +0100
Thomas Adam (thomas from edulinux.homeunix.org)


I'm hoping this will drum up some replies. I'm tumbling head-first into the world of python and ncurses for this, and know very little about both.

To cut a long (and rather boring) story short, I run irssi in a screen session on my poor P166 server. X11-forwarding is not an option as I don't have nor want X11 installed, and it's damn slow even if I did. But one useful feature is using one of the many scripts off of irssi's website, I can get irssi to scrape urls into a text file. "Wooooo, I hear you say".

Well, it is nice. And thanks to network transparency, I am able to tail that logfile via shfs (ssh filesystem, essentially). So then I got to thinking. What's an easy way of displaying the URLs in the file? I remembered a program that ships (often) with mutt -- "urlview". It scans a file for a regexp for URLs and presents a means of selecting them and launching them. Brilliant. Except... it expects a file -- piping to stdin blocks.

Bah! I don't want to hack the source-code, unblocked I/O in C is a headache. So I stumbled across pyurlview [1] a replacement written in Python. It's "ok" and is in a language I can read.

What I'm wanting to do is emulate this:

tail -f ./some_file | pyurlview

Now that doesn't work as-is. So I thought about it a bit, and came up with this little bit of python code (which I hope is the correct "way" to do it):

#! /usr/bin/env python
import os,sys

while 1:
  s = sys.stdin.readline()
  print "Got", s

Which seems to work when one does:

tail -f ./foo | testfile.py

So I thought I'd try and incorporate that idea into the pyurlview script [1] I tried all I might, to no avail. The closest I got was here [2] but that's mangling everything and isn't functioning like in the example I correctly showed above.

So if someone can see the error in logic, do say. Or does anyone know of an existing program that will do what I want? I can use any form of scripting language to do it (awk, ruby, etc) already -- but it's more the curses and non-blocking I/O I'm interested about. Plus, I'd rather not reinvent the wheel, hence battling it out with python. maybe I could use 'multitail' but it's UI sucks for what I am wanting.

Thanks In Advance,

-- Thomas Adam

[1] http://www.dgp.toronto.edu/~mac/code/projects/pyurlview.py

[2] http://edulinux.homeunix.org/~n6tadam/pyurlview-thomas.py

Which flavour?!

Tue, 8 Mar 2005 15:46:26 +0200
Gavin Kehlert (GavinK from LechabileSS.co.za)

Hi Guru's.

I'm a novice as far as Linux goes and want to attend a course but don't know which flavour to go for or who supplies the best training. From what I have seen my choice should be between RedHat and SuSE..

Any suggestions?

Thanks in advance,


Re: Possible correction to Introduction to Shell Scripting -

Wed, 6 Jul 2005 11:42:31 -0400
Benjamin A. Okopnik (editor from linuxgazette.net)
Question by peter.yellman (peter.yellman from webformation.com)

[ cc'd to The Answer Gang ]

Hi, Peter -

On Sat, Apr 09, 2005 at 11:53:18AM +0000, peter.yellman wrote: At http://linuxgazette.net/113/okopnik.html.

When it comes to shell scripting I am a rank novice, but it seemed to me that the passage "if $1 has a length of zero, then the following statements (echo... echo... exit) should be executed" (quotes not mine) should read "if $1 does not have a length of zero, then the following statements (echo... echo... exit) should be executed"

In fact, the article is correct - the

[ -z "$1" ] && { ... }

construct will execute the statement block if $1 is zero length; the "-z" operator returns "true" in that case. You can try it on the command line:

ben@Fenrir:~$ foo=abcdefg     # Give some value to 'foo'
ben@Fenrir:~$ [ -z "$foo" ] && echo "Foo is empty"
ben@Fenrir:~$ foo=     # Unset 'foo'
ben@Fenrir:~$ [ -z "$foo" ] && echo "Foo is empty"
Foo is empty

Thanks for the article,

You're welcome - glad you're enjoying it and thinking about it! :)

Re: [SEAPY] PyCon article

Fri, 8 Apr 2005 17:43:43 -0700 (MST)
Mike Orr (LG Contributing Editor)
Question by A group of Python users in Seattle (seattle-python from lists.seapig.org)

Dan Everhart wrote:

mso@oz.net wrote:

My PyCon 2005 article is up. Newbies will have to bear with some unexplained vocabulary (e.g., Lucerne, which is a full-text indexing system).

In case somebody wants to google, the correct spelling is "Lucene".

No wonder I couldn't find pyLucerne on Google!!!

-- Mike Orr

Speech Recognition (Not Voice)

Thu, 28 Apr 2005 11:04:30 -0400
jkinz (jkinz from kinz.org)

Hi Gang,

Just a quick note about the difference between "Voice recognition" and "Speech recognition".

Voice recognition means recognizing "The person who is speaking". This is a means of identifying people/persons by listening to their voice. We all do this whenever we use the phone and know who is on the other end as soon as they start talking.

Speech recognition means recognizing the words being spoken.

Voice recognition tools are used to identify people as part of access security systems.

Speech recognition tools (Dragon Naturally Speaking, ViaVoice) are used to "speak" into a computer microphone and have that computer understand what words you said. Currently Naturally Speaking seems to hold the edge in recognition accuracy. This can vary from person to person.

Janine's articles, [issue 113] Voice recognition shorthand and the birth of Weblish and [issue 87] Linux-Based Voice Recognition are actually about Speech recognition, not voice recognition.

-- Jeff Kinz, Emergent Research, Hudson, MA. (A former Speech Recognition software developer)

Thanks for clarifying the distinction, Jeff; we'll pass this on to our readers. I suspect that the common usage isn't likely to change much as a result - but, to misquote Larry Wall, I do occasionally struggle feebly against ignorance, and I admire other people's efforts in that direction as well. -- Ben


palmdoc problem

Sun, 1 May 2005 20:26:50 -0400
Wong Louis (mylover01ca from yahoo.com)

Hi, I am using debian unstable with firefox 1.0.2, I try to use the http://linuxgazette.net/cgi-bin/TWDT.pdb and put in the issue number. but it always d/l issue 113 no matter what I put in. I want to d/l the older issues in palmdoc format, how do I do it? Thanks

[Ben] Hi, Louis -
Well, being The Nice Guy that I am :), I've just tweaked the chunk of CGI that generates that file to be a bit more flexible; what you're asking for is now available. You can grab any past issue that contains a TWDT.html in PalmDoc format by going to
where NAME is the name of the issue. Do note, however, that
  1. Not all of the past LG issues have a TWDT.html (which is what's used to generate the PDB doc.)
  2. Issues before #100 are actually called "issueXX", where 'XX' is a two-digit issue number (i.e., leading zeros for low numbers.)
To make it simpler, you can use any sort of a bogus string for NAME, and you'll get a list of all issues with links that will return a PDB for that issue. I hope that helps.

This page edited and maintained by the Editors of Linux Gazette
HTML script maintained by Heather Stern of Starshine Technical Services, http://www.starshine.org/


Copyright © 2005, . Released under the Open Publication license unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 114 of Linux Gazette, May 2005

next -->