def _getPictures(album, conn, smugmug, lock): pictures = smugmug.images_get(AlbumID=album["id"], AlbumKey=album["Key"], Extras="MD5Sum,LastUpdated,FileName") albumId = pictures["Album"]["id"] for picture in pictures["Album"]["Images"]: lock.acquire() db.addSmugImage(conn,albumId, datetime.datetime.strptime(picture["LastUpdated"],'%Y-%m-%d %H:%M:%S'), picture["MD5Sum"], picture["Key"], picture["id"], picture["FileName"]) lock.release()
def run(self): #smugmug.images_upload(AlbumID=2,File='/Path/To/Image.jpg') while self._run: #grabs host from queue uploadImage = self._queue.get() albumid = uploadImage[0] filepath = uploadImage[1]+"/"+uploadImage[2] myLogger.debug("Starting upload of image '%s'", filepath) try: response = self._smugmug.images_upload(AlbumID=albumid,File=filepath) myLogger.debug("Finished upload of image '%s'. Now getting item info to log in db.", filepath) pictureFile = uploadImage[2] album = os.path.basename(os.path.dirname(pictureFile)) subcategory = os.path.basename(os.path.dirname(os.path.dirname(pictureFile))) category = os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(pictureFile)))) if category == "" or category == None: category = subcategory subcategory = None imageid = response["Image"]["id"] imagekey = response["Image"]["Key"] myLogger.debug("Image uploaded Key:'{0}' ID:'{1}'".format(imagekey, imageid)) response = self._smugmug.images_getInfo(ImageID=imageid, ImageKey=imagekey) myLogger.debug("Local MD5_SUM: {0} SmugMug: {1}".format(fileUtil.md5(filepath),response["Image"]["MD5Sum"])) self._lock.acquire() db.addSmugImage(self._conn,albumid, datetime.strptime(response["Image"]["LastUpdated"],'%Y-%m-%d %H:%M:%S'), response["Image"]["MD5Sum"], response["Image"]["Key"], response["Image"]["id"], response["Image"]["FileName"]) db.insertImageLog(self._conn, imageid, response["Image"]["FileName"], album, category, subcategory, datetime.now(), 'Upload') self._lock.release() myLogger.debug("Finished queued item.") except Exception, err: myLogger.error("Exception({0}): {1}".format(filepath,err)) traceback.print_exc(file=sys.stdout) #self._queue.put(uploadImage) #signals to queue job is done self._queue.task_done()