コード例 #1
0
ファイル: main.py プロジェクト: Pirnazar/gphoto
def create_album(title):
    from gphotospy import authorize
    from gphotospy.media import Media
    from gphotospy.album import Album
    CLIENT_SECRET_FILE = "gphoto_oauth.json"
    service = authorize.init(CLIENT_SECRET_FILE)
    album_manager = Album(service)

    new_album = album_manager.create(title)
    id_album = new_album.get("id")
    return id_album
コード例 #2
0
ファイル: sharing.py プロジェクト: valleedelisle/gphotospy
# Loop first 3 elements
for _ in range(3):
    try:
        # Print only albums's title (if present, otherwise None)
        print(next(album_iterator).get("title"))
    except (StopIteration, TypeError) as e:
        # Handle exception if there are no media left
        print("No (more) shared albums.")
        break

# Create a test album and share it
# create and share
print("Create and share a new album")

album_manager = Album(service)
created_album = album_manager.create('test shared album')
id_album = created_album.get("id")
share_info = album_manager.share(id_album)
token = share_info.get('shareToken')

# Using get() for info retrieval on the shared album
print("Getting album's info")
print(sharing_manager.get(token))

# Trying to join the shared album
print("Trying to join it")
try:
    sharing_manager.join(token)
except HttpError as e:
    print("Can't join albums already joined\n{}".format(e))
コード例 #3
0
# staging the media files (no description in this case)
for f in root.filename:
    media_manager.stage_media(f)

# actually put the uploaded media in a album
# (otherwise they can't be seen in Google Photos)
media_manager.batchCreate()

# batchCreate() when no name is given, uploads all media by default
# to a album named with the current date and time
# They are at this point also available ouside this album

# Some more album management #####

# create an album to add images to
created_album = album_manager.create('test album')
id_album = created_album.get("id")

# Show only media created though the API
media_manager.show_only_created(True)

# Now list will show first recently created media,
# and only those created with the API
list_iterator = media_manager.list()

items = []
added_images = len(root.filename)  # Recently added media number

for _ in range(added_images):
    media_item = next(list_iterator)
    items.append(media_item.get("id"))