Re: [pysqlite] list-pysqlite Digest, Vol 8, Issue 6

Fred <[email protected]> Sun, 26 Oct 2008 19:07:00 +0100
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
At 11:00 25/10/2008, Roger Binns wrote:
>The other solution is to read up all the results in one go so you 
>don't have to worry about the database changing while you are reading it.

Thank you for your help. Is this the correct way to download a web 
page, extract some information, and update a SQLite database using APSW?

=======
import sys, urllib, re, apsw

url = 
"http://www.amazon.fr/s/ref=nb_ss_gw?url=search-alias%3Daps&field-keywords="

connection=apsw.Connection("mybooks.sqlite")
cursor=connection.cursor()

rows=list(cursor.execute("SELECT isbn FROM books WHERE author IS NULL"))
cursor.execute("BEGIN")
p = re.compile('field-author=.+?">(.+?)</a> (Auteur)')
try:
         for row in rows:
                 for isbn in row:
                         if isbn:
                                 m=p.search(page,re.I | re.S | re.M)
                                 if m:
                                         author = m.group(1)
                                         sql="UPDATE books SET 
author=? WHERE isbn=?"
                                         cursor.execute(sql, (author, isbn))
         cursor.execute("END")
except:
    cursor.execute("ROLLBACK")
    raise

connection.close(True)
=======

Thank you.