add user index
This commit is contained in:
+22
-3
@@ -270,7 +270,7 @@ def get_token_via_gitlab(host: str, gitlab_url: str, username: str, password: st
|
||||
return session.cookies.get("MMAUTHTOKEN")
|
||||
|
||||
|
||||
def get_users(d: Driver) -> Tuple[Dict[str, str], str]:
|
||||
def get_users(d: Driver) -> Tuple[Dict[str, str], str, List[dict]]:
|
||||
my_user = d.users.get_user("me")
|
||||
my_username = my_user["username"]
|
||||
my_user_id = my_user["id"]
|
||||
@@ -278,6 +278,7 @@ def get_users(d: Driver) -> Tuple[Dict[str, str], str]:
|
||||
|
||||
# Get all usernames as we want to use those instead of the user ids
|
||||
user_id_to_name = {}
|
||||
user_profiles = []
|
||||
page = 0
|
||||
print("Downloading all user information... ", end="")
|
||||
while True:
|
||||
@@ -286,10 +287,27 @@ def get_users(d: Driver) -> Tuple[Dict[str, str], str]:
|
||||
break
|
||||
for user in users_resp:
|
||||
user_id_to_name[user["id"]] = user["username"]
|
||||
user_profiles.append(
|
||||
{
|
||||
"username": user.get("username") or "",
|
||||
"first_name": user.get("first_name") or "",
|
||||
"last_name": user.get("last_name") or "",
|
||||
"nickname": user.get("nickname") or "",
|
||||
}
|
||||
)
|
||||
page += 1
|
||||
print(f"Found {len(user_id_to_name)} users!")
|
||||
|
||||
return user_id_to_name, my_user_id
|
||||
return user_id_to_name, my_user_id, user_profiles
|
||||
|
||||
|
||||
def save_users_json(output_base: str, user_profiles: List[dict]) -> str:
|
||||
output_path = pathlib.Path(output_base) / "users.json"
|
||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
json.dump(user_profiles, f, indent=2, ensure_ascii=False)
|
||||
print(f"Saved user directory to '{output_path}'")
|
||||
return str(output_path)
|
||||
|
||||
|
||||
def select_team(d: Driver, my_user_id: str) -> str:
|
||||
@@ -731,7 +749,8 @@ if __name__ == '__main__':
|
||||
print("Please restart the script to reconfigure authentication.")
|
||||
raise SystemExit(1) from e
|
||||
raise
|
||||
user_id_to_name, my_user_id = get_users(d)
|
||||
user_id_to_name, my_user_id, user_profiles = get_users(d)
|
||||
save_users_json(output_base, user_profiles)
|
||||
team = select_team(d, my_user_id)
|
||||
channels = select_channel(d, team, my_user_id, user_id_to_name)
|
||||
for i_channel, channel in enumerate(channels):
|
||||
|
||||
Reference in New Issue
Block a user