Exemple #1
0
from init_photo_service import service
import pandas as pd

response = service.albums().list(
    pageSize=50,
    excludeNonAppCreatedData=False
).execute()
# get's albums information's : id, title, productURL, mediaItensCount, coverPhotoBaseUrl, coverPhotoMediaItemId
 
lstAlbums = response.get('albums')              # same result as response, cause there is no nextPageToken available
nextPageToken = response.get('nextPageToken')   # result is none to my library, cause I have less albuns than the pageSize limit

while nextPageToken:
    response = service.albums().list(
        pageSize=50,
        excludeNonAppCreatedData=False,
        pageToken=nextPageToken
    )
    lstAlbums.append(response.get('albums'))
    nextPageToken = response.get('nextPageToken')

# using pandas to better configure the lstAlbums created
df_albums = pd.DataFrame(lstAlbums)

my_album_id = df_albums[df_albums['title']=='My Family Photos']['id'][3]

# using this my_album_id, get information's about this album
response = service.albums().get(albumId=my_album_id).execute()


"""
from pprint import pprint
from init_photo_service import service
import pandas as pd
"""
search method (by album id)
"""
response_albums_list = service.albums().list().execute()
albums_list = response_albums_list.get('albums')

album_id = next(filter(lambda x: "Teste Frame" in x['title'],
                       albums_list))['id']

request_body = {'albumId': album_id, 'pageSize': 25}

response_search = service.mediaItems().search(body=request_body).execute()

lstMediaItems = response_search.get('mediaItems')
nextPageToken = response_search.get('nextPageToken')

while nextPageToken:
    request_body['pageToken'] = nextPageToken

    response_search = service.mediaItems().search(body=request_body).execute()
    lstMediaItems.extend(response_search.get('mediaItems'))
    nextPageToken = response_search.get('nextPageToken')

df_search_result = pd.DataFrame(lstMediaItems)
print(df_search_result)


def response_media_items_by_filter(request_body: dict):
Exemple #3
0
from init_photo_service import service
import pandas as pd
"""
create method
"""
request_body = {'album': {'title': 'My Family Photos'}}
# uses the request body above to create an album with the name 'My Family Photos'
response_album_family_photos = service.albums().create(
    body=request_body).execute()
Exemple #4
0
from init_photo_service import service
import pandas as pd
"""
Pandas configuration:

pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 50)
pd.set_option('display.max_colwidth', 32)
pd.set_option('display.width', 120)
pd.set_option('expand_frame_repr', True)
"""
"""
list method
"""
response = service.albums().list(pageSize=50,
                                 excludeNonAppCreatedData=False).execute()
# get's albums information's : id, title, productURL, mediaItensCount, coverPhotoBaseUrl, coverPhotoMediaItemId

print(response)  # print it
print(response.keys()
      )  # the dictionary keys are 'albums' and 'nextPageToken' if available

lstAlbums = response.get(
    'albums'
)  # same result as response, cause there is no nextPageToken available
nextPageToken = response.get(
    'nextPageToken'
)  # result is none to my library, cause I have less albuns than the pageSize limit

# if there is more albuns than the pageSize limit, iteration is necessary to get all albums
while nextPageToken:
# Reference: https://learndataanalysis.org/albums-resource-google-photos-api-and-python-part-2/

from init_photo_service import service
import pandas as pd
"""
list method
"""
response = service.albums().list(pageSize=50,
                                 excludeNonAppCreatedData=False).execute()

lstAlbums = response.get('albums')
nextPageToken = response.get('nextPageToken')

while nextPageToken:
    response = service.albums.list(pageSize=50,
                                   excludeNonAppCreatedData=False,
                                   pageToken=nextPageToken)
    lstAlbums.append(response.get('ablums'))
    nextPageToken = response.get('nextPageToken')

df_albums = pd.DataFrame(lstAlbums)
"""
get method
"""
my_album_id = df_albums[df_albums['title'] == 'Jay\'s Photo']['id'][0]
response = service.albums().get(albumId=my_album_id).execute()
print(response)
"""
create method
"""
request_body = {'album': {'title': 'My Family Photos'}}
Exemple #6
0
from init_photo_service import service
import pandas as pd
"""
batchAddMediaItems & batchRemoveMediaItems
"""

response = service.albums().list(pageSize=50,
                                 excludeNonAppCreatedData=False).execute()

lstAlbums = response.get('albums')
nextPageToken = response.get('nextPageToken')

while nextPageToken:
    response = service.albums.list(pageSize=50,
                                   excludeNonAppCreatedData=False,
                                   pageToken=nextPageToken)
    lstAlbums.append(response.get('albums'))
    nextPageToken = response.get('nextPageToken')

df_albums = pd.DataFrame(lstAlbums)

album_id = df_albums['id'][2]

response = service.mediaItems().list(pageSize=25).execute()

lst_medias = response.get('mediaItems')
nextPageToken = response.get('nextPageToken')

while nextPageToken:
    response = service.mediaItems().list(pageSize=25,
                                         pageToken=nextPageToken).execute()
import os
from Google import Create_Service
import pandas as pd  # pip install pandas
import requests  # pip install requests
from init_photo_service import service

pd.set_option('display.max_columns', 100)
pd.set_option('display.max_rows', 150)
pd.set_option('display.max_colwidth', 150)
pd.set_option('display.width', 150)
pd.set_option('expand_frame_repr', True)

myAblums = service.albums().list().execute()
myAblums_list = myAblums.get('albums')
dfAlbums = pd.DataFrame(myAblums_list)
Teste_Frame_album_id = dfAlbums[
    dfAlbums['title'] == 'Teste Frame']['id'].to_string(index=False).strip()


def download_file(url: str, destination_folder: str, file_name: str):
    response = requests.get(url)
    if response.status_code == 200:
        print('Downloading file {0}'.format(file_name))
        with open(os.path.join(destination_folder, file_name), 'wb') as f:
            f.write(response.content)
            f.close()


media_files = service.mediaItems().search(body={
    'albumId': Teste_Frame_album_id
}).execute()['mediaItems']