async def list_playlists():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        youtube_v3 = await aiogoogle.discover("youtube", "v3")
        req = youtube_v3.playlists.list(part="snippet", mine=True)
        res = await aiogoogle.as_user(req)
    pprint.pprint(res)
async def create_signup_document():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as google:
        firestore = await google.discover("firestore", "v1")
        await google.as_user(
            firestore.projects.databases.documents.createDocument(
                parent="projects/{project_name}/databases/(default)/documents",
                collectionId="signups",
                json=dict(
                    fields={
                        "email": {
                            "stringValue": email
                        },
                        "addedAt": {
                            "timestampValue":
                            datetime.datetime.utcnow().isoformat() + "Z"
                        },
                        "anotherString": {
                            "stringValue": 'anotherString'
                        },
                    }),
                validate=
                False,  # "parent" validation has an invalid pattern. Our input is actually valid.
            ),
            user_creds=user_creds,
        )
Ejemplo n.º 3
0
async def list_contacts():
    aiogoogle = Aiogoogle(user_creds=user_creds, client_creds=client_creds)
    people_v1 = await aiogoogle.discover("people", "v1")

    contacts_list = []

    def append_connections(connections):
        for connection in connections:
            phone_nums = connection.get("phoneNumbers")
            if phone_nums:
                num = phone_nums[0].get("canonicalForm")
            else:
                num = None

            if "names" not in connection:
                name = ""
            else:
                name = connection["names"][0]["displayName"]
            contacts_list.append({name: num})

    async with aiogoogle:
        pages = await aiogoogle.as_user(
            people_v1.people.connections.list(
                resourceName="people/me", personFields="names,phoneNumbers"),
            full_res=True,
        )
    async for page in pages:
        append_connections(page["connections"])

    pprint.pprint(contacts_list)
    print("Length:")
    print(len(contacts_list))
Ejemplo n.º 4
0
async def list_contacts():
    aiogoogle = Aiogoogle(user_creds=user_creds, client_creds=client_creds)
    people_v1 = await aiogoogle.discover('people', 'v1')

    contacts_list = []

    def append_connections(connections):
        for connection in connections:
            phone_nums = connection.get('phoneNumbers')
            if phone_nums:
                num = phone_nums[0].get('canonicalForm')
            else:
                num = None

            if 'names' not in connection:
                name = ''
            else:
                name = connection['names'][0]['displayName']
            contacts_list.append({name: num})

    async with aiogoogle:
        pages = await aiogoogle.as_user(people_v1.people.connections.list(
            resourceName='people/me', personFields='names,phoneNumbers'),
                                        full_res=True)
    async for page in pages:
        append_connections(page['connections'])

    pprint.pprint(contacts_list)
    print('Length:')
    print(len(contacts_list))
Ejemplo n.º 5
0
async def list_files():
    async with Aiogoogle(user_creds=user_creds, client_creds=client_creds) as aiogoogle:
        drive_v3 = await aiogoogle.discover("drive", "v3")
        res = await aiogoogle.as_user(drive_v3.files.list(), full_res=True)
    async for page in res:
        for file in page["files"]:
            print(f"{file.get('id')}: {file.get('name')}")
Ejemplo n.º 6
0
async def method_resource():
    async with Aiogoogle(user_creds=user_creds, client_creds=client_creds) as aiogoogle:
        name_version = await aiogoogle.discover('name', 'version')
        req = name_version.resource.method(parameterOne='uno', parameterTwo='deus')
        res = await aiogoogle.as_user(
            req
        )
    pprint.pprint(res)
Ejemplo n.º 7
0
async def method_resource():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        name_version = await aiogoogle.discover("name", "version")
        req = name_version.resource.method(parameterOne="uno",
                                           parameterTwo="deus")
        res = await aiogoogle.as_user(req)
    pprint.pprint(res)
Ejemplo n.º 8
0
async def list_events():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        calendar_v3 = await aiogoogle.discover("calendar", "v3")
        pages = await aiogoogle.as_user(
            calendar_v3.events.list(calendarId="primary"), full_res=True)
    async for page in pages:
        pprint.pprint(page)
Ejemplo n.º 9
0
async def stream_file(file_id):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        drive_v3 = await aiogoogle.discover("drive", "v3")

        # Stream the file
        await aiogoogle.as_user(
            drive_v3.files.get(fileId=file_id, pipe_to=MyFile(), alt="media"))
Ejemplo n.º 10
0
async def list_events():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds,
                         session_factory=CurioAsksSession) as aiogoogle:
        calendar_v3 = await aiogoogle.discover('calendar', 'v3')
        events = await aiogoogle.as_user(
            calendar_v3.events.list(calendarId='primary'), )
    pprint.pprint(events)
Ejemplo n.º 11
0
async def translate_to_latin(words):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds,
                         api_key=api_key) as aiogoogle:
        language = await aiogoogle.discover("translate", "v2")
        words = dict(q=[words], target="la")
        result = await aiogoogle.as_api_key(
            language.translations.translate(json=words))
    pprint.pprint(result)
async def list_events():
    async with Aiogoogle(
            user_creds=user_creds,
            client_creds=client_creds,
            session_factory=CurioAsksSession,
    ) as aiogoogle:
        calendar_v3 = await aiogoogle.discover("calendar", "v3")
        events = await aiogoogle.as_user(
            calendar_v3.events.list(calendarId="primary"))
    pprint.pprint(events)
Ejemplo n.º 13
0
async def list_events():
    async with Aiogoogle(
            user_creds=user_creds,
            client_creds=client_creds,
            session_factory=TrioAsksSession,
    ) as aiogoogle:
        calendar_v3 = await aiogoogle.discover("calendar", "v3")
        events = await aiogoogle.as_user(
            calendar_v3.events.list(calendarId="primary"), full_res=True)
    async for page in events:
        pprint.pprint(page)
Ejemplo n.º 14
0
async def upload_file(full_path, new_name):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        # Create API
        drive_v3 = await aiogoogle.discover("drive", "v3")

        # Upload file
        upload_res = await aiogoogle.as_user(
            drive_v3.files.create(upload_file=full_path,
                                  fields="id",
                                  json={"name": new_name}))
        print("Uploaded {} successfully.\nFile ID: {}".format(
            full_path, upload_res['id']))
Ejemplo n.º 15
0
async def get_email_headers():
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as google:
        gmail = await google.discover("gmail", "v1")

        response = await google.as_user(
            gmail.users.messages.list(userId="me", maxResults=1))
        key = response["messages"][0]["id"]
        email = await google.as_user(
            gmail.users.messages.get(userId="me", id=key))
    headers = email["payload"]["headers"]
    for header in headers:
        print(f"{header['name']}: {header['value']}")
Ejemplo n.º 16
0
async def upload_file(full_path, new_name):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        # Create API
        drive_v3 = await aiogoogle.discover("drive", "v3")

        # Upload file
        upload_res = await aiogoogle.as_user(
            drive_v3.files.create(upload_file=full_path, fields="id"))
        print("Uploaded {} successfully!".format(full_path))

        file_id = upload_res["id"]

        # Rename uploaded file
        await aiogoogle.as_user(
            drive_v3.files.update(fileId=file_id, json={"name": new_name}))
        print("Renamed {} to {} successfully!".format(full_path, new_name))
Ejemplo n.º 17
0
async def upload_file(full_path, new_name):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        # Create API
        drive_v3 = await aiogoogle.discover('drive', 'v3')

        # Upload file
        upload_res = await aiogoogle.as_user(
            drive_v3.files.create(upload_file=full_path, fields='id'))
        print('Uploaded {} successfully!'.format(full_path))

        file_id = upload_res['id']

        # Rename uploaded file
        await aiogoogle.as_user(
            drive_v3.files.update(fileId=file_id, json={'name': new_name}), )
        print('Renamed {} to {} successfully!'.format(full_path, new_name))
Ejemplo n.º 18
0
async def upload_file(full_path, new_name):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        # Create API
        drive_v3 = await aiogoogle.discover("drive", "v3")

        req = drive_v3.files.create(upload_file=full_path,
                                    fields="id",
                                    json={"name": new_name})

        # Usually autodetected by Drive
        # mimetypes autodetects the mimetype by file extension, which isn't always accurate.
        # You may want to manually enter this for some extra assurance.
        req.upload_file_content_type = mimetypes.guess_type(full_path)[0]

        # Upload file
        upload_res = await aiogoogle.as_user(req)
        print("Uploaded {} successfully.\nFile ID: {}".format(
            full_path, upload_res['id']))
Ejemplo n.º 19
0
async def download_file(file_id, dir_path):
    async with Aiogoogle(user_creds=user_creds,
                         client_creds=client_creds) as aiogoogle:
        drive_v3 = await aiogoogle.discover('drive', 'v3')

        # First get the name of the file
        info_res = await aiogoogle.as_user(drive_v3.files.get(fileId=file_id))

        # Make full path
        file_name = info_res['name']
        full_path = os.path.join(dir_path, file_name)

        # Second download the file
        await aiogoogle.as_user(drive_v3.files.get(fileId=file_id,
                                                   download_file=full_path,
                                                   alt='media'),
                                full_res=True)

        print('Downloaded file to {} successfully!'.format(full_path))
Ejemplo n.º 20
0
async def shorten_urls(long_url):
    async with Aiogoogle(api_key=api_key) as google:
        url_shortener = await google.discover("urlshortener", "v1")
        short_url = await google.as_api_key(
            url_shortener.url.insert(json=dict(longUrl=long_url)))
    return short_url