def writeMeta(self, photo, url): self.metaFile.write(photo_to_string(photo))
def handleResponse(self, response, numImages): self.currentCompletedImages = 0 self.currentSkippedImages = 0 self.currentBadURLs = 0 self.currentDiscardedImages = 0 self.currentFailedImages = 0 self.totalImagesQueried += numImages if numImages > config.maxPhotosPerPage: self.currentDiscardedImages += numImages - config.maxPhotosPerPage self.totalDiscardedImages += numImages - config.maxPhotosPerPage self.current_num_images = numImages for image in response[0]: if self.shouldStop: self.exitThread() if image != None: image = image.attrib image_id = str(image["id"]) # Check to see if this image has already been successfully downloaded. if self.is_downloaded(image_id): self.currentSkippedImages += 1 self.totalSkippedImages += 1 continue url = extract_url(image) if len(url) == 0: self.currentBadURLs += 1 self.totalBadURLs += 1 continue if not (self.isSupportedFormat(url)): self.currentBadURLs += 1 self.totalBadURLs += 1 continue imageName = self.getImageName(image_id) imagePath = self.get_image_path(imageName) imagePath = self.replaceExtension(imagePath, url) if config.download_image: download_image_done = download_image(url, imagePath) if download_image_done != True: self.logFile.write("ERROR: image download thread timed-out" + "\n") self.currentFailedImages += 1 self.totalFailedImages += 1 self.downloadProcess = None continue self.downloadProcess = None if config.createThumbnailEnabled: thumbnailPath = self.getThumbnailPath(imageName) success = self.createThumbnail(imagePath, thumbnailPath) else: if os.path.exists(imagePath) and os.path.getsize(imagePath) > 0: success = True else: success = False else: success = True # If the thumbnail was successfully created, write the meta data # data and log the success. if success: image_meta_file_path = self.get_meta_path(imageName) meta_file = open(image_meta_file_path, "w") meta_file.write("ID: " + imageName + "\n") meta_file.write(photo_to_string(image)) meta_file.write("\n") meta_file.close() self.metaFile.write("ID: " + imageName + "\n") self.writeMeta(image, url) self.metaFile.write("\n") self.currentCompletedImages += 1 self.totalCompletedImages += 1 self.completedFile.write(imageName + "\n") print(self.get_running_status(0)) else: self.currentFailedImages += 1 self.totalFailedImages += 1 current_status = self.get_running_status(2) self.logFile.write(current_status) print(current_status)