예제 #1
0
def main(team_id, channel, tab_name, tab_url):
    api = GraphApi(scopes=['Team.Create', 'TeamSettings.ReadWrite.All'])

    response = api.team.get_team(team_id)
    team = response.value
    print(team)

    channel_id = None
    if channel:
        response = api.team.list_channels(team_id)
        for ch in response.value:
            if ch.display_name.lower() == channel.lower():
                channel_id = ch.id
                break
    else:
        response = api.team.get_primary_channel(team_id)
        channel_id = response.value.id

    if not channel_id:
        raise Exception("Channel not found")

    response = api.team.add_tab_to_channel(team_id, channel_id, tab_name,
                                           tab_url)
    if response.ok:
        print("Created tab", response.value)
    else:
        print("Failed to create tab", response.text)
예제 #2
0
def main(name):
    api = GraphApi(scopes=['Group.ReadWrite.All'])
    response = api.team.list_teams()
    for team in response.value:
        if team.display_name == name or team.id == name:
            print("Deleting team", team.id)
            response = api.group.delete(team.id)
            if not response.ok:
                print(response.text)
예제 #3
0
def main(site):
    api = GraphApi(scopes="Files.Read.All")

    if site:
        site = SiteResource(name=site)
    else:
        site = SiteResource()

    response = api.sharepoint.list_drives(site)
    print(response.value)
예제 #4
0
def main(filenames, batch=False):
    api = GraphApi(scopes=["Files.Read.All"], batch=batch)

    responses = []
    for filename in filenames:
        response = api.files.parse_drive_item(filename)
        responses.append((filename, response))

    for filename, response in responses:
        print(f"Results for {filename}:")
        print(response.value)
예제 #5
0
def main(remote_file):
    api = GraphApi(scopes=["Files.Read.All"], batch=True)

    _, filename = api.files.parse_file_path(remote_file)
    response = api.files.parse_drive_item(remote_file)
    drive_item = response.value

    path = Path(filename)

    response = api.files.download_file(drive_item)
    with open(path.name, 'wb') as f:
        for chunk in response.response.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)
예제 #6
0
def main(name, description=None):
    api = GraphApi(scopes=['Team.Create', 'TeamSettings.ReadWrite.All'])
    team = Team(display_name=name, description=description)

    response = api.team.create_team(team)
    location = response.headers.get('Location')

    sleep(1)
    response = api.client.make_request(location).value
    while response.get("status") != 'succeeded':
        print("Creating team:", response.get("status"), end="\r")
        sleep(1)
        response = api.client.make_request(location).value

    print(response)
예제 #7
0
def main(name, starts_with, exact, channels, folder):
    api = GraphApi(scopes=["Group.Read.All"])

    response = api.team.list_teams(search=name,
                                   starts_with=starts_with,
                                   exact=exact)
    for team in response.value:
        print(f"{team.display_name} [{team.id}]")
        print(team.description)
        if channels or folder:
            response = api.team.list_channels(team.id)
            for ch in response.value:
                print(f"* {ch.display_name} [{ch.id}]")
                if folder:
                    response = api.team.get_channel_files_folder(
                        team.id, ch.id)
                    if response.ok:
                        folder = response.value
                        print(f"  {folder.web_url}")
                    else:
                        print("  [Folder not found]")
        print("")
예제 #8
0
    def __init__(self,
                 root: Union[str, DriveItem],
                 writeable=False,
                 client=None):
        self._lock = threading.RLock()
        super(FS, self).__init__()
        if client is None:
            self.__client = self.get_client(writeable)
        else:
            self.__client = client

        api = GraphApi(self.__client)

        try:
            if isinstance(root, DriveItem):
                drive_item = root
            else:
                drive_item, filename = api.files.parse_file_path(root)
                assert filename == "/"
                drive_item = drive_item.value
        except Exception as e:
            raise errors.CreateFailed(f"Could not open {root}: {e}") from e

        self._drive_root = self._resource_root = drive_item.get_api_reference()
        self.session = MSGraphyClientSession(self.__client,
                                             self._resource_root)

        self._meta = {
            'case_insensitive': True,
            'invalid_path_chars': ':\0\\',
            'max_path_length': None,  # don't know what the limit is
            'max_sys_path_length': None,  # there's no syspath
            'network': True,
            'read_only': False,
            'supports_rename': False  # since we don't have a syspath...
        }
예제 #9
0
def main(name):
    api = GraphApi(scopes=["Sites.Read.All"])

    response = api.sharepoint.list_sites(search=name)
    for site in response.value:
        print(site, end="\n\n")