from websockets.sync.client import connect import json import random import sys import re # 'groupProfile' # displayName # send_message = "#tesr SimpleX is really great." # send_message = "/c " # send_message = "/gp tesr" chat = "https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fu2dS9sG8nMNURyZwqASV4yROM28Er0luVTx5X1CsMrU%3D%40smp4.simplex.im%2FFZScXyGUCmbSINL837cLOlEdpTGusx4d%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEA2VHcAyxrlxX9eWXIU-VkkXHzsfLGd9KrAPOZ7U36qAs%253D%26srv%3Do5vmywmrnaxalvz6wi3zicyftgio6psuvyniis6gco6bp6ekl4cqj4id.onion" group = r"https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F8SfErsx9mxKxDf43tG28e3d3AY53ExYg%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEAY0E79e_79XZn-nWhzjTjubWsKbUTR2DPqyjXGOSkY1k%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22groupLinkId%22%3A%22kEFv_MuLHSiq6teQ87hqYg%3D%3D%22%7D" error_group = r"https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_z=%7B%22groupLinkId%22%3A%22kEFv_MuLHSiq6teQ87hqYg%3D%3D%2%7D" deleted_group = r"https://simplex.chat/contact#/?v=2-7&smp=smp%3A%2F%2Fhpq7_4gGJiilmz5Rf-CswuU5kZGkm_zOIooSw6yALRg%3D%40smp5.simplex.im%2F13jrHyHfGDSROmVb3a54C6fsF7rfYpkX%23%2F%3Fv%3D1-3%26dh%3DMCowBQYDK2VuAyEAd5Zap4vAhLICUvUJo-mSY-6lgYX_-EqTI7saDuypsQ8%253D%26srv%3Djjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion&data=%7B%22groupLinkId%22%3A%22m1HwUMtTE-cOLcz9x9fGSw%3D%3D%22%7D" # group_name = response['resp']['groups'][2][0]['groupProfile']['displayName'] # def is_simplex_url_valid(simplex_link: str): # with connect("ws://localhost:3030") as websocket: # query = f"/groups" # command = { # 'corrId': f"id{random.randint(0,999999)}", # 'cmd': query, # } # websocket.send(json.dumps(command)) # message = websocket.recv() # response = json.loads(message) # number_of_groups = len(response['resp']['groups']) # try: # with open("dave.txt",'r+') as f: # for i in range(0,number_of_groups): # f.seek(0) # group_name = response['resp']['groups'][i][0]['groupProfile']['displayName'] # file_values = f.read().splitlines() # if group_name in file_values: # continue # else: # f.write(f"{group_name}\n") # except Exception as e: # print(f"end {e}") # is_simplex_url_valid(group) def is_simplex_link_valid(simplex_link: str) -> bool: """ Connects to the group using the `simplex_link`. If the response contains error False will be returned else True. """ with connect("ws://localhost:3030") as websocket: query = f"/c {simplex_link}" command = { 'corrId': f"id{random.randint(0,999999)}", 'cmd': query, } websocket.send(json.dumps(command)) message = websocket.recv() response = json.loads(message) repsonse_type = response['resp']['type'] print(repsonse_type) if 'error' in repsonse_type.lower(): return False elif 'deleted' in repsonse_type.lower(): return False return True result = is_simplex_link_valid(deleted_group) print(result) # def save_to_csv_file(): # pass # def check_simplex_url_and_join(simplex_link: str): # with connect("ws://localhost:3030") as websocket: # query = f"/c {simplex_link}" # desc_query = f"/gp {simplex_link}" # command = { # 'corrId': f"id{random.randint(0,999999)}", # 'cmd': query, # } # websocket.send(json.dumps(command)) # message = websocket.recv() # response = json.loads(message) # link_type = response['resp']['type'] # # group_name = response['resp']['groupInfo']['groupProfile']['displayName'] # command = { # 'corrId': f"id{random.randint(0,999999)}", # 'cmd': desc_query, # } # websocket.send(json.dumps(command)) # message = websocket.recv() # response = json.loads(message) # print(response) # # group_desc = response['resp']['groupInfo']['groupProfile']['displayName']['description'] # print(response['resp']) # # print(f"{response['resp']['groupInfo']['groupProfile']['displayName']}") # check_simplex_url_and_join(group)