what's wrong here? (search script)

Brendan Fay fay.brendan at gmail.com
Thu Jul 6 13:27:59 EDT 2006


Dear Someone:

     I have written a script that accesses the googleAPI through
pygoogle and saves each of the ten documents as a .txt file by using a
specific function for each respective file type (.doc, .pdf, .html) to
convert it to such.  Everything works fine, except that I am trying to
make it search and return another result in the event that a file type
other than .doc, .pdf, .html, or .txt comes up.  Python is new to me
and I'm not sure why my method doesn't work.  I'd really appreciate any
advice; here is the relevant code:

def searchhelper(words, start=0, max=10):
	data = google.doGoogleSearch(words)
	objlist = data.results
	urllist = map((lambda x: x.URL), objlist)
	return urllist


def searchhelper2(initwords, urls, counter):
	for url in urls:
		if findinlink(url, 'pdf'): # all these functions are defined
elsewhere,
			convertpdf(url)  # fbut they definitely are working properly
		elif findinlink(url, 'htm'):
			converthtml(url)
		elif findinlink(url, 'txt'):
			urllib.urlretrieve(url, parse(x))
		elif findinlink(url, 'doc'):
			convertdoc(url)
		elif not findinlink(url, '.'):
			converthtml(url)
		else:
			urllist = urls[counter + 1:] + searchhelper(initwords, 11 + counter,
1) # (I'm
			searchhelper2(initwords, urllist, counter + 1)# assuming this is
where I have      #
                                  erred; however, I'm not sure)


def search(initwords):
	urllist = searchhelper(initwords)
	searchhelper2(initwords, urllist, 0)

Thanks,
Brendan




More information about the Python-list mailing list