extract news article from web

Steve Holden steve at holdenweb.com
Wed Dec 22 21:34:11 CET 2004

Steve Holden wrote:


> However, the code to extract the news is pretty simple. Here's the whole 
>  program, modulo newsreader wrapping. It would be shorter if I weren't 
> stashing the extracted links it a relational database:

I see that, as is so often the case, I only told half the story, and you 
will be wondering what the "db" module does. The main answer is adapts 
the same logic to two different database modules in an attempt to build 
a little portability into the system (which may one day be open sourced).

The point is that MySQLdb requires a "%s" in queries to mark a 
substitutable parameter, whereas mxODBC requires a "?". In order to work 
around this difference the db module is imported by anything that uses 
the database. This makes it easier to migrate between different database 
technologies, though still far from painless, and allows testing by 
accessing a MySQL database directly and via ODBC as another option.

Significant strings have been modified to protect the innocent.
# db.py: establish a database connection with
#        the appropriate parameter style
         import MySQLdb as db
         conn = db.connect(host="****", db="****",
                  user="****", passwd="****")
         pmark = "%s"
         print "Using MySQL"
except ImportError:
         import mx.ODBC.Windows as db
         conn = db.connect("****", user="****", password="****")
         pmark = "?"
         print "Using ODBC"
Steve Holden               http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC      +1 703 861 4237  +1 800 494 3119

More information about the Python-list mailing list