def send_update_personal_data(self, request): for target_ID in self.friend_list: target = self.ip_address_dict[target_ID] data = asyncio.run_coroutine_threadsafe( send_request_handle.client_main(json.dumps(request), target), self.loop) print(data.result())
def send_add_friend_request(self, request, target): asyncio.run_coroutine_threadsafe( send_request_handle.client_main(json.dumps(request), target), self.loop) if target in self.waiting_response_list: return self.waiting_response_list.append(target) self.update_source()
def send_add_friend_reply(self, request, target_ID): self.friend_request_list.remove(target_ID) target = self.ip_address_dict.get(target_ID) self.check_file_exists() asyncio.run_coroutine_threadsafe( send_request_handle.client_main(json.dumps(request), target), self.loop) if request['body']['response']: self.send_personal_data(target) self.update_source()
def send_personal_data(self, target): with open(f'../learn/images/{self.my_data["background_picture"]}', 'rb') as fp: background_picture = str(base64.b64encode(fp.read()), "utf-8") with open(f'../learn/images/{self.my_data["profile_picture"]}', 'rb') as fp: profile_picture = str(base64.b64encode(fp.read()), "utf-8") my_data = \ { "header": "update_personal_data", "body": { "personal_data_list": [ { "ID": self.my_data["ID"], "user_name": self.my_data["user_name"], "background_picture": { "binary": background_picture, 'file_type': self.my_data['background_picture'].split('.')[-1] }, "profile_context": self.my_data["profile_context"], "profile_picture": { "binary": profile_picture, 'file_type': self.my_data['profile_picture'].split('.')[1] }, "latest_edit_time": self.my_data["latest_edit_time"] } ] } } asyncio.run_coroutine_threadsafe( send_request_handle.client_main(json.dumps(my_data), target), self.loop)
def send_like_up(self, request): for target_ID in self.friend_list: target = self.ip_address_dict[target_ID] asyncio.run_coroutine_threadsafe( send_request_handle.client_main(json.dumps(request), target), self.loop)