Python Script To Download Wallpapers from InterfaceLift

75 pts.
Tags:
Contests
IT Scripts
Python
Python scripts
Wallpaper
Language: Python Purpose: Downloads Wallpapers from InterfaceLift and stores them in your home Folder Here is the Code:



   #!/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]
ASKED: October 6, 2011  1:02 PM
UPDATED: April 30, 2012  9:13 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

This doesn’t work anymore. Plz fix!

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Razrak
    Sorry for a noob question. How can I make this python script into an executable in windows?
    10 pointsBadges:
    report
  • BobBeechey
    Go to
    report
  • BobBeechey
    I cannot see the link http://www.logix4u.net/component/content/article/27-tutorials/44-how-to-create-windows-executable-exe-from-python-script in my answer above
    750 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following