def downloadBooks(self,titles=None,formats=None): #titles= list('C# tutorial', 'c++ Tutorial') ; format=tuple('pdf','mobi','epub','code')
        try:
            #download ebook
            if formats is None:
                formats=('pdf','mobi','epub','code')   
            if titles is not None:
                tempBookData = [data for i,data in enumerate(self.bookData) if any(data['title']==title for title in titles) ]
            else:
                tempBookData=self.bookData
            nrOfBooksDownloaded=0
            for i, book in enumerate(tempBookData):
                for format in formats:
                    #print(format)
                    if format in list(tempBookData[i]['downloadUrls'].keys()):
                        if format == 'code':
                            fileType='zip'
                        else:
                            fileType = format
                        formattedTitle= ''.join(list(map(str.capitalize, tempBookData[i]['title'].split(' '))))
                        for ch in ['?',':','*','/']:
                            if ch in formattedTitle:
                                formattedTitle=formattedTitle.replace(ch,'_')
                        fullFilePath=os.path.join(self.downloadFolderPath,formattedTitle+'.'+fileType)
                        if(os.path.isfile(fullFilePath)):
                            print(fullFilePath+" already exists")
                            pass
                        else:
                            if format == 'code':
                                print("downloading code for eBook: '"+tempBookData[i]['title']+ "'...")                           
                            else:
                                print("downloading eBook: '"+tempBookData[i]['title']+"' in '."+format+ "' format...")
                            r = self.session.get(self.packtPubUrl+tempBookData[i]['downloadUrls'][format],timeout=100)
                            if(r.status_code is 200):
                                with open(fullFilePath,'wb') as f:
                                    f.write(r.content)
                                if format == 'code':
                                    print("[SUCCESS] code for eBook: '"+tempBookData[i]['title']+"' downloaded succesfully!")                           
                                else:
                                    print("[SUCCESS] eBook: '"+tempBookData[i]['title']+'.'+format+"' downloaded succesfully!")      
                                nrOfBooksDownloaded=i+1
                            else:
                                raise requests.exceptions.RequestException("Cannot download "+tempBookData[i]['title'])                            
            print(str(nrOfBooksDownloaded)+" eBooks have been downloaded !")          
        except requests.exceptions.RequestException as exception:
            print("[ERROR] - Exception occured during GET request%s "%exception )
        except __HOLE__ as exception:
            print("[ERROR] - Exception occured durin opening file %s "%exception )
dataset/ETHPy150Open igbt6/Packt-Publishing-Free-Learning/packtFreeBookDownloader.py/MyPacktPublishingBooksDownloader.downloadBooks