[Tutor] Get it, Parse it, Dump it....

alan.gauld@bt.com alan.gauld@bt.com
Thu, 14 Jun 2001 16:50:22 +0100


> From the winPython interpreter, one line at a time, I do this:
> >>> import urllib
> >>> x=urllib.urlopen("http://site.that.has.the.data/search?etc=stuff")   
> >>> print x.readlines()
> 
> And this shows everything on one LONG line 
> ...
> I have been able to use string.split to break the line into a 
> list on the TAB character.
> 
> Not sure how to go about building this into something that 
> can run on its own instead of the command prompt.

OK the easy bit first ;-)

Just open a new empty text file and type in the commands 
that you entered at the >>> prompt. ie the ast line would 
look like:

print x.readlines()

insert as the first line:

#! /usr/bin/env python

Save the file as fetchdata.py or whatever and make it executable
and then run it. (I'm assuming since you mentioned chron(cron?) 
that you are on a Linux/Unix platform...)

If you are on windows(coz you mention OCDB below) you don't need 
the special first line above and can just save the file and 
then run it by double clicking in windoze exploder.

> Also need to know how to connect to and talk to my ODBC 
> defined database (Access2000) and then take the fields, 
> one line at a time, and insert them
> into the DB table.

For that you need some SQL - do you know SQL?
If not then I think Access has some tools that generate it 
for you and you could copy it into your program but its 
really better if you learn basic SQL - its easy enough...

> I am using Zope so if there is a way to build this into a 
> script or external method and call it from Zope that 

My limited understanding of Zope says that if you wrap 
the code as a function inside the file then you can call 
it from Zope. I'm sure theres some extra magic but ...

To create a function just do:

def doit():
   # add your lines here all indented by a constant amount

The Zope URL will then be:

http://<www.some.domain/zoperoot/fetchdata/doit

Where fetchdata is your file and doit the function you defined.

As Patrick says it's an interesting problem but you need 
to tackle it bit by bit and ask us specific questions.

You look to be on the rght track.

Alan G