def _cache_albums_async(app, refresh_thumbnails=False, refresh_dates=False): with app.app_context(): album_manager = GPhotosAlbum(service) current_ids = list() for a in album_manager.list(): album = Album.query.filter_by(gphotos_id=a.get("id")).first() if not album: album = Album() album.gphotos_id = a.get("id") if not album.end_date or refresh_dates: start_date, end_date = _get_album_date_range(album.gphotos_id) album.start_date = start_date album.end_date = end_date current_ids.append(a.get("id")) album.title = a.get("title") album.url_title = normalize_for_url(a.get("title")) album.items_count = a.get("mediaItemsCount") db.session.add(album) thumbnail = os.path.join(app.config["ALBUM_THUMB_PATH"], a.get("id") + ".jpg") if not os.path.exists(thumbnail) or refresh_thumbnails: urllib.request.urlretrieve( a.get("coverPhotoBaseUrl") + "=w300-h200-c", os.path.join(app.config["ALBUM_THUMB_PATH"], a.get("id") + ".jpg"), ) db.session.commit() # delete from db albums no longer in google photos stmt = delete(Album).where( Album.gphotos_id.notin_(current_ids)).execution_options( synchronize_session="fetch") db.session.execute(stmt) db.session.commit()
search_iterator = media_manager.search(filter=[ FEATUREFILTER.NONE, # This is default, didn't need be specified CONTENTFILTER.TRAVEL, CONTENTFILTER.SELFIES, MEDIAFILTER.ALL_MEDIA, # This too is default... date(2020, 4, 24), date_range(start_date=date(2020, 4, 19), end_date=date(2020, 4, 21)) ]) try: print(next(search_iterator)) except (StopIteration, TypeError) as e: print("No media found :-(") # Search for media in album print("Search media in album") # get an album's id album_manager = Album(service) album_iterator = album_manager.list() album = next(album_iterator) album_id = album.get("id") album_title = album.get("title") print("Album title: {}".format(album_title)) # search in album search_iterator = media_manager.search_album(album_id) try: for _ in range(3): print(next(search_iterator).get("filename")) except (StopIteration, TypeError) as e: print("No (more) media in album {}.".format(album_title))