[Zope] URL Substitution.
Bill Anderson
bill.anderson@libc.org
Fri, 11 Feb 2000 17:15:04 -0700
"Alexandre A. Rodioukov" wrote:
>
> Ok, I'm posting followup to my one posting :) What I did, I finally
> decided to write external method. Here follows the code:
>
> [ http_fetch.py ]
> def fetch_file(uri):
> from httplib import HTTP
> from urlparse import urlparse
>
> parsed_uri=urlparse(uri)
>
> h = HTTP(parsed_uri[1])
> h.putrequest('GET', parsed_uri[2])
> h.putheader('Accept', 'text/html')
> h.putheader('Accept', 'text/plain')
> h.endheaders()
> errcode, errmsg, headers = h.getreply()
> if errcode == 200:
> f = h.getfile()
> return f.read()
> [EOF]
> While calling you need to pass argument(uri) taht points to document
> you want to fetch.
>
> Works fine for me :) Hope that would be useful. Comments and
> suggestions are always very welcome to simuran@home.com
Some sites return a list that you may want or need to munge into links.
An example would be LinuxToday.com.
Add this to the above, and you it will return a list ready for
formatting.
def fetch_list(uri):
from httplib import HTTP
from urlparse import urlparse
parsed_uri=urlparse(uri)
h = HTTP(parsed_uri[1])
h.putrequest('GET', parsed_uri[2])
h.putheader('Accept', 'text/html')
h.putheader('Accept', 'text/plain')
h.endheaders()
errcode, errmsg, headers = h.getreply()
items=[]
if errcode == 200:
f = h.getfile()
for line in f.readlines():
items.append(line)
return items
Of coourse, this means that unless it is a list of links, complete with
HTML, you will need to do some splitting of the string returned in the
list, but it will be a start.
I am looking at making this into something that can be integrated with
the PTK ... along with KnowledgeKit. No promises on a timeframe ;) ( I
do have an intermediary PTK-Aware KnowledgeKit if anyone wants it, I'll
put it up for grabs.).
An example of the use of the lists visit http://www.libc.org/TheIgloo .
Bill
--
In flying I have learned that carelessness and overconfidence are
usually far more dangerous than deliberately accepted risks.
-- Wilbur Wright in a letter to his father, September 1900