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')
def create_photoset_missing_photos_on_local(database, flickr): flickrphotos = database.select_missing_flickr_photos() if flickrphotos: idlist = [] for row in flickrphotos: idlist.append(row['id']) photoscsv = general.list_to_csv(idlist) photosetname = '{name} {date}'.format(name=PHOTOSET_MISSING, date=datetime.datetime.now().strftime(general.FLICKR_DATE_FMT)) primaryphotoid = flickrphotos[0]['Id'] photosetid = flickr.photoset_create(photosetname, primaryphotoid) assert photosetid, 'photosetId is Null' flickr.photoset_edit(photosetid, primaryphotoid, photoscsv) else: logger.info('No missing photos on local')
def __wait_until_uploading_complete(self, tickets): completed = False notcomplete = list(tickets) while not completed: response = self.api.photos.upload.checkTickets( tickets=general.list_to_csv(notcomplete)) notcomplete.clear() for ticket in response.find('uploader'): logger.info('id<%s>, complete<%s>, invalid<%s>' % (ticket.get('id'), ticket.get('complete'), ticket.get('invalid'))) if ticket.get('complete') == '0': notcomplete.append(ticket.get('id')) if len(notcomplete): logger.info('waiting to complete uploading of <%d> pictures' % len(notcomplete)) time.sleep(5) else: completed = True