Exemplo n.º 1
0
def reshelf(images,  imageDir, historyFile):
    """
    Store image reference in the history file if its not there yet and if we
    actually can find it on Flickr.
    """

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

    for image in images:
        # remove absolute directory
        image = image[len(imageDir):]
        # its better to always reopen this file
        uploaded = shelve.open( historyFile )
        if uploaded.has_key(str(image)):
            continue
        # each picture should have one id tag in the folder format with spaces
        # replaced by # and starting with #
        flickrtag = '#' + image.replace(' ','#')
        photo = getPhotoIDbyTag(flickrtag, user)
        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()
Exemplo n.º 2
0
def createSets(uploadedNow, historyFile):
    """
    Create/update all sets for the photos just uploaded
    """
    logging.debug("tags2set: Started tags2set")
    try:
        user = flickr.test_login()
        if not user.id:
            return None
        existingSets = user.getPhotosets()
    except:
        logging.error(sys.exc_info()[0])
        return None

    uploaded = shelve.open(historyFile)
    keys = uploaded.keys()
    keys.sort()
    uploadedSets = set()
    for uploadedid in uploadedNow:
        try:
            image = uploaded[str(uploadedid)]
        except KeyError:
            continue
        uploadedSets.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 uploadedSets:
            continue

        if not lastSetName == setName and not lastSetName == "":
            # new set is starting so save last
            _creatSet(photoSet, lastSetName, existingSets)
            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 uploadedSet in uploadedSets:
        if uploadedSet not in existing or uploadedSet not in createdSets:
            _creatSet(
                [
                    uploaded.get(photo)
                    for photo in keys
                    if (photo.find(os.path.sep) != -1 and image2set(photo) == uploadedSet)
                ],
                uploadedSet,
                existingSets,
            )
            createdSets.add(uploadedSet)
Exemplo n.º 3
0
def reshelf(images, imageDir, historyFile):
    """
    Store image reference in the history file if its not there yet and if we
    actually can find it on Flickr.
    For each file, store the following information:
    - Photo ID from Flickr
    - Modification time
    - Size of file
    """

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

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