Greetings. I did not write the below code. I got it from Click Here

Thanks for any help.

When I try to check the syntax it gives me an error on the very last line of code. The error "SyntaxError:invalid syntax (line 119, offset 26):a.getWallpaperList()[/pre]

#!/usr/bin/env python
import urllib2
import urllib
import re
import os
import threading
import sys
class IliftDownloader(object):
        """Downloads InterfaceLift wallpappers
        """

        def __init__(self,dir = os.environ['HOME']+"/IliftWallpapers",nThreads=5):
            """
            """
            self.__totalpages = -1
            self.__currentPageNumber = -1
            self.__currentImage = -1
            self.__approximateImageTotal = -1
            self.percentage = -1
            self.__dir=dir
            self.__nThreads = nThreads
            self.stop=False
            self.__threadList = []
        def getWallpaperList(self):
            """
            """
            self.stop=False
            if not os.path.exists(self.__dir):
                os.mkdir(self.__dir)
            os.chdir(self.__dir)
            #page = urllib2.urlopen("http://www.interfacelift.com/wallpaper_beta/downloads/date/any/")
            page = urllib2.urlopen("http://interfacelift.com/wallpaper/downloads/date/widescreen/index1.html")
            stringResponse = page.read()
            pattern = re.compile(r'page 1 of (d+)')
            matcher = pattern.search(stringResponse)
            #print stringResponse
            if matcher:
                self.__totalpages = int(matcher.group(1))
            else:
                sys.exit(-1)
            #print self.__totalpages
            pagesPerThread = self.__totalpages/self.__nThreads
            for u in range(self.__nThreads):
                if u!=self.__nThreads-1:
                    self.__threadList.append(threading.Thread(target=self.__getWallpaperListAux, args =(u*pagesPerThread,(u+1)*pagesPerThread)))
                else:
                    self.__threadList.append(threading.Thread(target=self.__getWallpaperListAux,args=(u*pagesPerThread,self.__totalpages)))
            for trd in self.__threadList:
                trd.start()
                trd.join()

        def __getWallpaperListAux(self,start,end):
            """
            """
            for i in range(start,end):
                if self.stop == True:
                    break
                self.__currentPageNumber= i
                get = urllib2.urlopen("http://interfacelift.com/wallpaper/downloads/date/any/index"+str(i)+".html")
                stringResponse = get.read()
                pattern = re.compile(r"http://interfacelift.com/wallpaper/previews/.+?.jpg")
                lista = pattern.findall(stringResponse)
                self.__approximateImageTotal = len(lista)*self.__totalpages
                for link in lista:
                    if self.stop == True:
                        break
                    retry = 0
                    found =  False
                    for j in range(6):
                        if (not found):
                            res = None
                            if(j==0):
                                res = "2560x1600"
                            elif (j==1):
                                res = "2560x1440"
                            elif (j == 2):
                                res = "1920x1200"
                            elif(j == 3):
                                res = "1680x1050"
                            elif(j == 4):
                                res = "1440x900"
                            else:
                                res = "1280x800"

                            imgUrl=str.replace(str.replace(link,"previews","7yz4ma1",1),".jpg","_"+res+".jpg",1)
                            urlParts = str.split(imgUrl,"/")
                            filename= urlParts[-1]
                            if(os.path.exists(filename)):
                                self.__currentImage+=1
                                self.percentage = 100* float(self.__currentImage)/self.__approximateImageTotal
                                print "Download Percentage %3.2f" %self.percentage
                                break
                            else:
                                try:
                                    (fname,headers)=urllib.urlretrieve(imgUrl,filename)
                                    #If your IP is BlackListed Stpos Downloading Images and exits, you can resume at a latter time
                                    if headers.get("Content-Length")=='0':
                                        os.remove(fname)
                                        print "You IP must be currently blackListed, please resume download at a latter time"
                                        sys.exit(1)
                                    found = True
                                    self.__currentImage+=1
                                    print "Download Percentage %3.2f" %self.percentage
                                except(), e:
                                    print e
                                    os.remove(filename)
                                    self.__currentImage-=1
                                    if(retry < 3):
                                        retry+=1
                                        print"retrying"+imgUrl
                                        j-=1
                                        found = False
                                    else:
                                        retry = 0
                                retry = 0

if __name__ == '__main__':
         a = IliftDownloader()
         a.getWallpaperList()[/pre]

remove the junk [/pre]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.