Beispiel #1
0
def _download_and_scan_unmatched_flickr_photos(database,
                                               directory,
                                               dryrun=True,
                                               noprompt=False,
                                               nodatematch=False):
    flickrphotos = database.select_unmatchable_flickr_photos(nodatematch)

    success = False

    if flickrphotos:
        if noprompt or general.query_yes_no(
                'Do you want to download and scan <%d> unmatched pictures from Flickr'
                % len(flickrphotos)):

            downloaddirectory = os.path.join(directory,
                                             general.APPLICATION_NAME)
            local.download_photos(directory=downloaddirectory,
                                  flickrphotos=flickrphotos,
                                  dryrun=dryrun)
            _search_local(database, downloaddirectory)

            success = True

    else:
        logger.info('No unmatched Flickr photos found')
        success = True

    logger.debug('success <{success}>'.format(success=success))
    return success
Beispiel #2
0
def do_sync(database, flickr, directory, twoway=False, dryrun=True, noprompt=False, nodatematch=False, identifymissing=False):
    if noprompt or general.query_yes_no('Do you want to sync the local file system with Flickr'):
        threads = []

        minuploaddate = 0 if identifymissing else -1

        thread = threading.Thread(target=_search_flickr, args=(database, flickr, minuploaddate,))
        threads.append(thread)

        thread = threading.Thread(target=_search_local, args=(database, directory,))
        threads.append(thread)

        for thread in threads:
            thread.start()

        for thread in threads:
            thread.join()

        if _download_and_scan_unmatched_flickr_photos(database, directory, dryrun=dryrun, noprompt=noprompt, nodatematch=nodatematch):
            _tag_matched_flickr_photos(database, flickr, directory, dryrun=dryrun, noprompt=noprompt)
            _do_upload(database, flickr, directory, dryrun=dryrun, noprompt=noprompt)

            if identifymissing:
                create_photoset_missing_photos_on_local(database, flickr)

            elif twoway:
                _download_missing_photos_from_flickr(database, directory, dryrun=dryrun, noprompt=noprompt)
Beispiel #3
0
def _tag_matched_flickr_photos(database,
                               flickr,
                               directory,
                               dryrun=True,
                               noprompt=False):
    localphotos = database.select_unmatched_photos_with_flickr_id()

    success = False

    if localphotos:
        if noprompt or general.query_yes_no(
                'Do you want to tag <%d> matched pictures found on Flickr' %
                len(localphotos)):
            try:
                _add_tags(flickr, localphotos, dryrun=dryrun)

            finally:
                minuploaddate = database.select_min_upload_date_without_signature(
                )
                _search_flickr(database, flickr, minuploaddate=minuploaddate)
                success = True

    else:
        logger.info('No matched Flickr photos found')
        success = True

    logger.debug('success <{success}>'.format(success=success))
    return success
Beispiel #4
0
def _download_missing_photos_from_flickr(database, directory, dryrun=True, noprompt=False):
    flickrphotos = database.select_missing_flickr_photos()

    if flickrphotos:
        if noprompt or general.query_yes_no('Do you want to download <%d> missing photos from Flickr' % len(flickrphotos)):
            local.download_photos(directory=directory, flickrphotos=flickrphotos, dryrun=dryrun)
            _search_local(database, directory)
    else:
        logger.info('No missing photos to download')
Beispiel #5
0
def create_photosets(database, flickr, rootpath, noprompt=False):
    photosets = _get_flickr_photosets(database, flickr)
    directories = database.get_directories_from_local()

    if len(directories):
        if noprompt or general.query_yes_no(
                'Potentially create / delete <%s> photosets on Flickr?' %
                len(directories)):
            photosetsused = []

            for directory in directories:
                photos = general.list_from_rows(
                    database.select_flickr_photos_matching_local_by_directory(
                        directory))

                if photos:
                    photosetname = general.get_photoset_name(
                        directory, rootpath)
                    photoscsv = general.list_to_csv(photos)

                    primaryphotoid = photos[0]
                    photosetid = database.get_photoset_id(photosetname)

                    if photosetid:
                        logger.info('Photoset already exists on Flickr <%s>' %
                                    photosetname)
                    else:
                        photosetid = flickr.photoset_create(
                            photosetname, primaryphotoid)

                    assert photosetid, 'photosetId is Null'

                    # replace photos in set
                    flickr.photoset_edit(photosetid, primaryphotoid, photoscsv)
                    photosetsused.append(str(photosetid))

                else:
                    logger.warning(
                        'No photos found on Flickr match local photos found in <%s>'
                        % directory)

            if photosetsused:
                flickr.delete_unused_photosets(photosetsused=photosetsused,
                                               photosets=photosets)
            else:
                logger.warning('no photosets in use')
    else:
        logger.info('No local photo directories found')
Beispiel #6
0
def delete_tags(database, flickr, stringmatch, dryrun=True, noprompt=False):
    assert stringmatch, 'stringmatch not supplied'
    flickrphotos = database.select_all_flickr_photos_matching_tag(stringmatch)
    logger.info(
        'Deleting tags containing STRING<{stringmatch}> from <{count}> Flickr photos'
        .format(count=len(flickrphotos), stringmatch=stringmatch))

    if flickrphotos:
        if noprompt or general.query_yes_no(
                'Deleting tags containing STRING<{stringmatch}> from <{count}> Flickr photos'
                .format(count=len(flickrphotos), stringmatch=stringmatch)):
            data = []
            for flickrphoto in flickrphotos:

                newtags = general.remove_tag_from_tags(flickrphoto['tags'],
                                                       stringmatch)

                data.append((flickrphoto['id'], newtags))

            chunksize = math.ceil(len(data) / THREAD_COUNT_TAGS)

            logger.debug('data<%d>, chunksize<%d>' % (len(data), chunksize))
            assert chunksize, 'Chunksize'

            if dryrun:
                logger.info('Dry run, not deleting tags')
            else:
                threads = []
                for chunk in general.chunks(data, chunksize):
                    thread = threading.Thread(target=_set_tags_worker,
                                              args=(
                                                  flickr,
                                                  chunk,
                                              ))
                    threads.append(thread)

                for thread in threads:
                    thread.start()

                for thread in threads:
                    thread.join()

                _search_flickr(database, flickr, minuploaddate=0)
    else:
        logger.info('No matching Flickr tags found')
Beispiel #7
0
def _do_upload(database, flickr, directory, dryrun=True, noprompt=False):
    uploadphotos = database.select_photos_for_upload()

    logger.info('Selected <%d> photos for upload to Flickr' % len(uploadphotos))

    passed = 0
    failed = 0

    if dryrun:
        logger.info('Dry run, not uploading')
    else:
        if uploadphotos:
            if noprompt or general.query_yes_no('Upload <%d> pictures to Flickr?' % len(uploadphotos)):
                passed, failed = flickr.upload_photos(uploadphotos)

                if passed > 0:
                    _search_flickr(database, flickr)
        else:
            logger.info('No photos to upload')

    logger.info('Uploaded: passed<%d>, failed<%d>' % (passed, failed))
    return passed
Beispiel #8
0
def delete_tables(database, noprompt=False):
    if noprompt or general.query_yes_no('Delete the database?', default='no'):
        database.drop_local_photos_table()
        database.drop_flickr_photos_table()
        database.create_local_photos_table()
        database.create_flickr_photos_table()
Beispiel #9
0
def rebase_flickr(database, flickr, noprompt=False):
    if noprompt or general.query_yes_no('Rebase the Flickr database?', default='no'):
        database.drop_flickr_photos_table()
        database.create_flickr_photos_table()
        _search_flickr(database, flickr, minuploaddate=0)