what's wrong here? (search script)

B

Brendan Fay

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
 
M

Michael Fisher

Brendan said:
I figured it out. Is there any way to delete your own posts?

Brendan said:
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

Instead of deleting the previous post, you should post the solution for
all to learn from.

desNotes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top