Created
April 3, 2025 03:39
-
-
Save Heilum/79931c11060d888ecdb2dadbe67d04cf to your computer and use it in GitHub Desktop.
A pyhton script the reset your getStream chat data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from stream_chat import StreamChat | |
# instantiate your stream client using the API key and secret | |
# the secret is only used server side and gives you full access to the API | |
server_client = StreamChat( | |
api_key="xxxx", api_secret="ttttt") | |
token = server_client.create_token("admin_user") | |
# print(token) | |
if __name__ == "__main__": | |
# Filter for messaging type channels | |
filter = {"type": "messaging"} | |
# Query channels with a limit (max 30 per query) | |
response = server_client.query_channels(filter, limit=100) | |
# print("channels:", len(response)) | |
# print("response:", response) | |
channels = response.get("channels", []) | |
# Print CIDs | |
cids = [] | |
for channel in channels: | |
cid = channel['channel']['cid'] | |
cids.append(cid) | |
print("总共需要删除的channel数量:", len(cids)) | |
if len(cids) > 0: | |
server_client.delete_channels(cids=cids, hard_delete=True) | |
print("删除成功") | |
# delete all users | |
users = server_client.query_users( | |
{} | |
) | |
for user in users["users"]: | |
if user['id'] != "a" and user['id'] != "b": | |
server_client.delete_user(user_id=user['id']) | |
print(f"Deleted user: {user['id']}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment