Please help with Python Script/MS-Access (DAO)

Dave dave5774 at hotmail.com
Mon Jun 17 17:44:36 EDT 2002


Hey all,
I'm having trouble writing a Python script relating to Microsoft Access.  If
anyone could help me I would greatly appreciate it.  Here's the problem :

I built an MS-Access table with 5 columns(fields) : OrderID, OrderDate,
PlantID, ProductID, OrderQty, with OrderID as the primary key.  All fields
are numeric, except for OrderDate(which is a date field).

Now I want to populate this table with data from a web page
(http://opim.wharton.upenn.edu/~opim101/spring02/Plant1.html).  please check
the site.

My object is to read the the data and insert it record by record into my
Access table.

Here's what I have so far :

import urllib, string
Plant1 =
urllib.urlopen('http://opim.wharton.upenn.edu/~opim101/spring02/Plant1.html'
)
lines1 = Plant1.readlines()
import win32com.client
engine = win32com.client.Dispatch("DAO.DBEngine.35")
db=engine.OpenDatabase(r'd:\Plants.mdb')

I have several problems :
Firstly, when I read the lines, I notice that not all of them are relevant.
I need to ignore <html>, <body>, etc. at the beginning of the file, as well
as the column headers, so that the action really begins from line 4 of the
file and ends with </body>
Also, I need to eliminate <p> from every line in the file in order to get to
the five comma-delimited fields that follow, and then split the rest of the
string to get to each field.  Here's what I think part of the code should
look like :

for line in lines1.readlines():
    line=line.rstrip()
    inOrderID,inOrderDate,inRegionID,inProductID,inOrderQty =
line.split(",")

Something like that, I'm not sure...
Lastly, now that I've read all the fields, I need to insert them each as a
single record into my table of my access database using Python DAO using the
Insert statement.  Also, the OrderDate field that I read in, looks like a
text type to Access, so I need to pad it with the # sign on either side
before inserting it into the Access database, so that Access interprets it
as a Date/Time type.

Finally, I need to get the same information from 2 other plants and tag them
onto the same table...from the web page
http://opim.wharton.upenn.edu/~opim101/spring02/PlantPortal.html
where plant1's data shows up first, plant2's data shows up below it, and
plant3's data shows up last...so all plants' data in the same table.

If anyone could help me by writing the script I would greatly appreciate
it...
Thank you so much.
Sincerely,
Dave






More information about the Python-list mailing list