Exemple #1
0
    def uploadImage( self, image ):
        folderTag = image[len(IMAGE_DIR):]
        #print folderTag
        #return
        if ( not self.uploaded.has_key( folderTag ) ):

            try:
                logging.debug( "Getting EXIF for %s" % image)
                f = open(image, 'rb')
                exiftags = exif.process_file(f)
                f.close()
                #print exiftags[XPKEYWORDS]

                
                #print folderTag
                #make one tag equal to original file path with spaces replaced by # and start it with # (for easier recognition) since space is used as TAG separator by flickr
                # this is needed for later syncing flickr with folders 
                realTags  = folderTag.replace('\\',' ')   # look for / or \ or _ or .  and replace them with SPACE to make real Tags 
                realTags =  realTags.replace('/',' ')   # these will be the real tags ripped from folders
                realTags =  realTags.replace('_',' ')
                realTags =  realTags.replace('.',' ')  
                picTags = '#' + folderTag.replace(' ','#') + ' ' + realTags

                if exiftags == {}:
                   logging.debug( 'NO_EXIF_HEADER for %s' % image)
                else:
                   if XPKEYWORDS in exiftags:  #look for additional tags in EXIF to tag picture with
                            if len(exiftags[XPKEYWORDS].printable) > 4:
                                picTags += exif.make_string( eval(exiftags[XPKEYWORDS].printable)).replace(';',' ')
                
                #print picTags
                logging.debug( "Uploading image %s" % image)
                photo = ('photo', image, open(image,'rb').read())


                d = {
                    api.token   : str(self.token),
                    api.perms   : str(self.perms),
                    "tags"      : str(picTags),
                    "is_public" : str( FLICKR["is_public"] ),
                    "is_friend" : str( FLICKR["is_friend"] ),
                    "is_family" : str( FLICKR["is_family"] )
                }
                sig = self.signCall( d )
                d[ api.sig ] = sig
                d[ api.key ] = FLICKR[ api.key ]
                url = self.build_request(api.upload, d, (photo,))
                xml = urllib2.urlopen( url ).read()
                res = xmltramp.parse(xml)
                if ( self.isGood( res ) ):
                    logging.debug( "successful.")
                    self.logUpload( res.photoid, folderTag )
                else :
                    print "problem.."
                    self.reportError( res )
            except:
                logging.error(sys.exc_info())
    def uploadImage( self, image ):
        folderTag = image[len(IMAGE_DIR):]

        if self.uploaded.has_key(folderTag):
            return None

        try:
            logging.debug( "Getting EXIF for %s" % image)
            f = open(image, 'rb')
            exiftags = exif.process_file(f)
            f.close()
            #print exiftags[XPKEYWORDS]
            #print folderTag
            # make one tag equal to original file path with spaces replaced by
            # # and start it with # (for easier recognition) since space is
            # used as TAG separator by flickr

            # this is needed for later syncing flickr with folders
            realTags  = os.path.dirname(folderTag).replace('\\',' ')   # look for / or \ or _ or .  and replace them with SPACE to make real Tags
            realTags =  realTags.replace('/',' ')   # these will be the real tags ripped from folders
            realTags =  realTags.replace('_',' ')
            realTags =  realTags.replace('.',' ')
            realTags = realTags.strip()

            if configdict.get('full_folder_tags', 'false').startswith('true'):
                realTags = os.path.dirname(folderTag).split(os.sep)
                realTags = (' '.join('"' + item + '"' for item in  realTags))

            picTags = '#' + folderTag.replace(' ','#') + ' ' + realTags

            if exiftags == {}:
                logging.debug( 'NO_EXIF_HEADER for %s' % image)
            else:
                if XPKEYWORDS in exiftags:  #look for additional tags in EXIF to tag picture with
                    if len(exiftags[XPKEYWORDS].printable) > 4:
                        picTags += exif.make_string( eval(exiftags[XPKEYWORDS].printable)).replace(';',' ')

            picTags = picTags.strip()
            msg = "Uploading image %s with tags %s" % (image, picTags)
            timestamp = time.strftime('[%F %H:%M:%S]', time.localtime())
            logging.debug(msg)
            print timestamp, msg
            photo = ('photo', image, open(image,'rb').read())


            d = {
                api.token   : str(self.token),
                api.perms   : str(self.perms),
                "tags"      : str(picTags),
                "hidden"    : str( FLICKR["hidden"] ),
                "is_public" : str( FLICKR["is_public"] ),
                "is_friend" : str( FLICKR["is_friend"] ),
                "is_family" : str( FLICKR["is_family"] )
            }
            sig = self.signCall( d )
            d[ api.sig ] = sig
            d[ api.key ] = FLICKR[ api.key ]
            url = self.build_request(api.upload, d, (photo,))
            xml = urllib2.urlopen( url ).read()
            res = xmltramp.parse(xml)
            if ( self.isGood( res ) ):
                logging.debug( "successful.")
                self.logUpload( res.photoid, folderTag )
                return res.photoid
            else :
                print "problem.."
                self.reportError( res )
        except KeyboardInterrupt, ex:
            logging.debug("Keyboard interrupt seen, abandon uploads")
            print "Stopping uploads..."
            self.abandonUploads = True
            return None
Exemple #3
0
    def uploadImage(self, image):
        folderTag = image[len(IMAGE_DIR):]

        if (not self.upl.has_key(folderTag)):

            try:
                logging.debug("UploadThread %d Getting EXIF for %s" %
                              (self.threadID, image))
                f = open(image, 'rb')
                exiftags = exif.process_file(f)
                f.close()
                #print exiftags[XPKEYWORDS]

                #print folderTag
                #make one tag equal to original file path with spaces replaced by # and start it with # (for easier recognition) since space is used as TAG separator by flickr
                # this is needed for later syncing flickr with folders
                realTags = folderTag.replace(
                    '\\', ' '
                )  # look for / or \ or _ or .  and replace them with SPACE to make real Tags
                realTags = realTags.replace(
                    '/',
                    ' ')  # these will be the real tags ripped from folders
                realTags = realTags.replace('_', ' ')
                realTags = realTags.replace('.', ' ')
                picTags = '#' + folderTag.replace(' ', '#') + ' ' + realTags

                if exiftags == {}:
                    logging.debug('UploadThread %d NO_EXIF_HEADER for %s' %
                                  (self.threadID, image))
                else:
                    if XPKEYWORDS in exiftags:  #look for additional tags in EXIF to tag picture with
                        if len(exiftags[XPKEYWORDS].printable) > 4:
                            picTags += exif.make_string(
                                eval(exiftags[XPKEYWORDS].printable)).replace(
                                    ';', ' ')

                #print picTags
                logging.debug("UploadThread %d Uploading image %s" %
                              (self.threadID, image))
                photo = ('photo', image, open(image, 'rb').read())

                d = {
                    api.token: str(self.upl.token),
                    api.perms: str(self.upl.perms),
                    "tags": str(picTags),
                    "is_public": str(FLICKR["is_public"]),
                    "is_friend": str(FLICKR["is_friend"]),
                    "is_family": str(FLICKR["is_family"])
                }
                sig = self.upl.signCall(d)
                d[api.sig] = sig
                d[api.key] = FLICKR[api.key]
                url = self.upl.build_request(api.upload, d, (photo, ))
                xml = urllib2.urlopen(url).read()
                res = xmltramp.parse(xml)
                if (self.upl.isGood(res)):
                    logging.debug("successful.")
                    self.upl.logUpload(res.photoid, folderTag)
                else:
                    print "problem.."
                    self.upl.reportError(res)
            except:
                logging.error(sys.exc_info())