-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathfollow_user.py
More file actions
35 lines (26 loc) · 1.2 KB
/
Copy pathfollow_user.py
File metadata and controls
35 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Follow or unfollow a user (toggles the current state).
https://learn.microsoft.com/en-us/sharepoint/dev/apis/people-rest-api
"""
import argparse
from office365.sharepoint.client_context import ClientContext
from tests.settings import cert_path, cert_thumbprint, client_id, site_url, tenant
def main():
parser = argparse.ArgumentParser(description="Follow or unfollow a user")
parser.add_argument("--user", required=True, help="Account name of the user to follow/unfollow")
args = parser.parse_args()
ctx = ClientContext(site_url).with_client_certificate(
tenant, client_id=client_id, thumbprint=cert_thumbprint, cert_path=cert_path
)
user = ctx.web.ensure_user(args.user).execute_query()
if user.login_name is None:
raise SystemExit(f"User '{args.user}' could not be resolved")
is_following = ctx.people_manager.am_i_following(user.login_name).execute_query()
if is_following.value:
ctx.people_manager.stop_following(user.login_name).execute_query()
print(f"Unfollowed: {user.login_name}")
else:
ctx.people_manager.follow(user.login_name).execute_query()
print(f"Following: {user.login_name}")
if __name__ == "__main__":
main()