generated from thoth-station/template-project
-
Notifications
You must be signed in to change notification settings - Fork 13
/
get_member_userid.py
executable file
·60 lines (43 loc) · 1.82 KB
/
get_member_userid.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# Sefkhet-Abwy
# Copyright(C) 2019-2022 The Authors of Project Thoth
#
# This program is free software: you can redistribute it and / or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Sesheta's actions."""
import asyncio
import os
import logging
import typing
from httplib2 import Http
from apiclient.discovery import build, build_from_document
from httplib2 import Http
from oauth2client.service_account import ServiceAccountCredentials
from thoth.common import init_logging
init_logging()
_LOGGER = logging.getLogger(__name__)
SPACE = os.getenv("SESHETA_THOTH_DEVOPS_SPACE", None)
def main():
"""Get a List of user from a Google Chat Space and print it to stdout."""
if SPACE is not None:
scopes = ["https://www.googleapis.com/auth/chat.bot"]
credentials = ServiceAccountCredentials.from_json_keyfile_name("sesheta-chatbot-b5a97b40eeab.json", scopes)
http_auth = credentials.authorize(Http())
chat = build("chat", "v1", http=http_auth)
response = chat.spaces().members().list(parent=SPACE)
if response is not None:
r = response.execute()
for member in r["memberships"]:
print(f"\"{member['member']['displayName']}\": \"{member['member']['name'].replace('users/', '')}\",")
if __name__ == "__main__":
main()