def reshelf(images,  imageDir, historyFile, numThreads):
     
    logging.debug('flickr2history: Started flickr2history')
    try:
        global user
        user = flickr.test_login()
        logging.debug(user.id)
    except:
        logging.error(sys.exc_info()[0])
        return None 

    imageQueue = Queue.Queue();
    for image in images:
        imageQueue.put_nowait(image)

    global uploaded
    uploaded = shelve.open( historyFile )   #its better to always reopen this file

    global lock
    lock = threading.Lock()
    threads = []
    for i in range(numThreads):
        thread = ReshelfThread(i, imageDir, imageQueue, historyFile)
        threads.append(thread) 
        thread.start()

    for thrd in threads:
        thrd.join()

    uploaded.close()

    logging.debug('flickr2history: Finished flickr2history')
def reshelf(images,  imageDir, historyFile):
     
     logging.debug('flickr2history: Started flickr2history')
     try:
         global user
         user = flickr.test_login()
         logging.debug(user.id)
     except:
         logging.error(sys.exc_info()[0])
         return None
        
     for image in images:
        image = image[len(imageDir):] #remove absolute directory
        uploaded = shelve.open( historyFile )   #its better to always reopen this file
        if ( not uploaded.has_key(str(image) ) ):
                  #each picture should have one id tag in the folder format with spaces replaced by # and starting with #
                  flickrtag = '#' + image.replace(' ','#')
                  photo = getPhotoIDbyTag(flickrtag)
                  logging.debug(image)
                  if(not photo):
                       uploaded.close()  # flush the DB file
                       continue
                  logging.debug("flickr2history: Reregistering %s photo in local history file" % image)
                  uploaded[ str(image)] = str(photo.id)
                  uploaded[ str(photo.id) ] =str(image)
                  uploaded.close()
Exemple #3
0
def set_from_tags(tags, title, description, all=True):
    """all=True means include non-public photos"""
    user = flickr.test_login()
    photos = flickr.photos_search(user_id=user.id, auth=all, tags=tags)
    set = flickr.Photoset.create(photos[0], title, description)
    set.editPhotos(photos)
    return set
Exemple #4
0
def set_from_tags(tags, title, description, all=True):
    """all=True means include non-public photos"""
    user = flickr.test_login()
    photos = flickr.photos_search(user_id=user.id, auth=all, tags=tags)
    set = flickr.Photoset.create(photos[0], title, description)
    set.editPhotos(photos)
    return set
def search_perso():
    flickr.email = '*****@*****.**'
    flickr.password = '******'

    #To do only the first time
    if (False):
        permission = "read"
        myAuth = flickr.Auth()
        frob = myAuth.getFrob()
        link = myAuth.loginLink(permission, frob)
        raw_input("Please make sure you are logged into Flickr in Firefox")
        firefox = os.popen('firefox \"' + link + '\"')
        raw_input(
            "A Firefox window should have opened. Press enter when you have authorized this program to access your account"
        )
        token = myAuth.getToken(frob)
        f = file('token.txt', 'w')
        f.write(token)
        f.close()

    #user = flickr.people_findByEmail(flickr.email)
    user = flickr.test_login()
    print user.username
    photoList = flickr.photos_search(user.id, True,
                                     '')  #can be used to search by theme

    urls = []
    for photo in photoList:
        urls.append(getURL(photo, 'Large', False))

    for url in urls:
        print url
def search_perso():
    flickr.email = '*****@*****.**'
    flickr.password = '******'
    
    #To do only the first time
    if (False):
        permission = "read"
        myAuth = flickr.Auth()
        frob = myAuth.getFrob()
        link = myAuth.loginLink(permission,frob)
        raw_input("Please make sure you are logged into Flickr in Firefox")
        firefox=os.popen('firefox \"'+link+'\"')
        raw_input("A Firefox window should have opened. Press enter when you have authorized this program to access your account")
        token = myAuth.getToken(frob)
        f = file('token.txt','w')
        f.write(token)
        f.close()


    #user = flickr.people_findByEmail(flickr.email)
    user = flickr.test_login()
    print user.username
    photoList = flickr.photos_search(user.id, True, '')#can be used to search by theme
    
    urls = []
    for photo in photoList:
        urls.append(getURL(photo, 'Large', False))

    for url in urls:
        print url
def reshelf(images, imageDir, historyFile):

    logging.debug('flickr2history: Started flickr2history')
    try:
        global user
        user = flickr.test_login()
        logging.debug(user.id)
    except:
        logging.error(sys.exc_info()[0])
        return None

    for image in images:
        image = image[len(imageDir):]  #remove absolute directory
        uploaded = shelve.open(
            historyFile)  #its better to always reopen this file
        if (not uploaded.has_key(str(image))):
            #each picture should have one id tag in the folder format with spaces replaced by # and starting with #
            flickrtag = '#' + image.replace(' ', '#')
            photo = getPhotoIDbyTag(flickrtag)
            logging.debug(image)
            if (not photo):
                uploaded.close()  # flush the DB file
                continue
            logging.debug(
                "flickr2history: Reregistering %s photo in local history file"
                % image)
            uploaded[str(image)] = str(photo.id)
            uploaded[str(photo.id)] = str(image)
            uploaded.close()
def reshelf(images, imageDir, historyFile, numThreads):

    logging.debug('flickr2history: Started flickr2history')
    try:
        global user
        user = flickr.test_login()
        logging.debug(user.id)
    except:
        logging.error(sys.exc_info()[0])
        return None

    imageQueue = Queue.Queue()
    for image in images:
        imageQueue.put_nowait(image)

    global uploaded
    uploaded = shelve.open(historyFile)  #its better to always reopen this file

    global lock
    lock = threading.Lock()
    threads = []
    for i in range(numThreads):
        thread = ReshelfThread(i, imageDir, imageQueue, historyFile)
        threads.append(thread)
        thread.start()

    for thrd in threads:
        thrd.join()

    uploaded.close()

    logging.debug('flickr2history: Finished flickr2history')
def deleteAllPics( ):
        
        global user

        try:
             user = flickr.test_login()
             logging.debug(user.id)
        except:
            logging.error(sys.exc_info()[0])
            return None

        if(deleteAll.startswith('true') == False):
            return #check again to be sure if to go one

        logging.debug('deleteAll: Started Delete')
        retries = 0
        
        #this may take very long time !!!!
        while (retries < 3):
            try:
                    photos = []
                    logging.debug(user.id)
                    np = flickr.photos_search_pages(user_id=user.id, auth=all, per_page="500")
                    numPages = int(np)
                    i = 1
                    logging.debug("found %d num pages" % numPages)
                    while ( numPages > 0):
                        spage = str(i)
                        photos.extend(flickr.photos_search(user_id=user.id, auth=all, per_page="500", page=spage))
                        logging.debug( "added %d page to %d pic" % (i, len(photos)))
                        
                        numPages = numPages - 1
                        i = i + 1
                        
                    logging.debug( "got all %d pics to delete" % len(photos))
                    break
            except:
                    logging.error("deleteAll: Flickr error while searching ....retrying")
                    logging.error(sys.exc_info()[0])
                    
            retries = retries + 1
            
        if (not photos or len(photos) == 0):
            logging.debug("deleteAll: No files in Flickr to delete" )
            return None

        logging.debug("deleteAll: found %d media files to delete" % (len(photos)))
        while (len(photos)>1):
            try:
                photos.pop().delete()
                print "deleting pic " 
                logging.debug("deleteAll: Removed one image... %d images to go" % (len(photos)))

            except:
                logging.error("deleteAll: Flickr error while deleting image")
                logging.error(sys.exc_info()[0])

        logging.debug("deleteAll: DONE DELETING - NOTHING ELSE TO DO - EXITING")
        os._exit(1)    
def get_all_sets():
    """Gets the names for all sets on the account"""
    set_names = []
    user = flickr.test_login()
    sets = user.getPhotosets()
    for set in sets:
        set_names.append(set.title)
    return set_names
def get_single_set(set_name):
    """Gets a single set sets on the account"""
    user = flickr.test_login()
    sets = user.getPhotosets()
    target_set = None
    for set in sets:
        if (set.title == set_name):
            target_set = set
    return target_set
Exemple #12
0
def createSets(uploaded_now, historyFile):
    global existingSets
    global user

    logging.debug('tags2set: Started tags2set')
    try:
        user = flickr.test_login()
        logging.debug(user.id)
        existingSets=user.getPhotosets()
    except:
        logging.error(sys.exc_info()[0])
        return None

    uploaded = shelve.open( historyFile )
    keys = uploaded.keys()
    keys.sort()
    uploaded_sets = set()
    for uploadedid in uploaded_now:
        try:
            image = uploaded[str(uploadedid)]
        except KeyError:
            continue
        uploaded_sets.add(image2set(image))

    lastSetName = ''
    photoSet = []
    createdSets = set()
    setName = ''
    for image in keys:
        if image.find(os.path.sep) == -1: #filter out photoid keys
            continue
        setName = image2set(image)
        # only update sets that have been modified this round
        if setName not in uploaded_sets:
            continue

        if (not lastSetName == setName and not lastSetName == ''):
            #new set is starting so save last
            creatSet(photoSet, lastSetName)
            createdSets.add(lastSetName)
            photoSet = []
        logging.debug("tags2set: Adding image %s" % image)
        photoSet.append(uploaded.get(image))
        lastSetName = setName

    existing = set([setentry.title for setentry in existingSets])
    for uploaded_set in uploaded_sets:
        if uploaded_set not in existing and uploaded_set not in createdSets:
            photoSet = [uploaded.get(photo) for photo in keys if photo.find(os.path.sep) != -1 and image2set(photo) == uploaded_set]
            creatSet(photoSet, uploaded_set)
Exemple #13
0
def createSets(uploaded_now, historyFile):
    global existingSets
    global user

    logging.debug("tags2set: Started tags2set")
    try:
        user = flickr.test_login()
        logging.debug(user.id)
        existingSets = user.getPhotosets()
    except:
        logging.error(sys.exc_info()[0])
        return None

    uploaded = shelve.open(historyFile)
    keys = uploaded.keys()
    keys.sort()
    uploaded_sets = set()
    for uploadedid in uploaded_now:
        try:
            image = uploaded[str(uploadedid)]
        except KeyError:
            continue
        uploaded_sets.add(image2set(image))

    lastSetName = ""
    photoSet = []
    setName = ""
    for image in keys:
        if image.find(os.path.sep) > -1:  # filter out photoid keys
            setName = image2set(image)
            # only update sets that have been modified this round
            if setName not in uploaded_sets:
                continue

            if not lastSetName == setName and not lastSetName == "":
                # new set is starting so save last
                creatSet(photoSet, lastSetName)
                photoSet = []
            logging.debug("tags2set: Adding image %s" % image)
            photoSet.append(uploaded.get(image))
            lastSetName = setName

    # dont forget to create last set
    if len(photoSet) > 0:
        creatSet(photoSet, setName)
Exemple #14
0
def createSets( historyFile):
     global existingSets
     global user
    
     logging.debug('tags2set: Started tags2set')
     try:
         user = flickr.test_login()
         logging.debug(user.id)
         existingSets=user.getPhotosets()
     except:
         logging.error(sys.exc_info()[0])
         return None
     
     uploaded = shelve.open( historyFile )
     keys = uploaded.keys()
     keys.sort()
     lastSetName =''
     photoSet =[]
     setName = ''
     for image in keys:
        if(image.startswith('\\') or image.startswith('/')): #filter out photoid keys
            if(onlySubs.startswith('true')):
                head, setName = os.path.split(os.path.dirname(image))
            else:
                setName = os.path.dirname(image) #set name is realy a directory
                    
            if(not lastSetName == setName and not lastSetName == ''):
                #new set is starting so save last
                #logging.debug( "Creating set %s with %d pictures" % (lastSetName, len(photoSet)) )
                creatSet(photoSet, lastSetName)
                photoSet = []
            logging.debug("tags2set: Adding image %s" % image)
            photoSet.append(uploaded.get(image))
            lastSetName = setName
          
                
     #dont forget to create last set
     #logging.debug( "Creating set %s with %d pictures" % (setName, len(photoSet)) )
     creatSet(photoSet, setName)