import akinator from src.server import Server aki = akinator.Akinator() q = aki.start_game() server_port = int(sys.argv[1]) server_name = sys.argv[2] server = Server(server_name, server_port) server.create_socket() start_message, client_address = server.listen() if start_message == 'start': while aki.progression <= 80: server.send_message(q + '\n\t', client_address) a, client_address = server.listen() if a == "b": try: q = aki.back() except akinator.CantGoBackAnyFurther: pass else: q = aki.answer(a) aki.win() server.send_message( f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t", client_address) correct, client_address = server.listen() if correct.lower() == "yes" or correct.lower() == "y":
class Remote: def __init__(self, options): self.opts = options self.local_sign = options.local_sign self.server = Server(self) self.status = {"ledger_index": 0} self.requests = {} self.cache = LRUCache(100) # 100 size,为cache和path设置缓存 self.path = LRUCache(2100) # 2100 size def submit(self, command, data, filter, callback): if (isfunction(callback)): req_id = self.server.send_message(command, data) self.requests[req_id] = { # 此处还有些代码逻辑没实现 # 根据command, data, filter, callback生成新的request对象 } # def subscribe(self, address, secret): # data = { # "command": "subscribe", # "account": address, # "secret": secret # } # self.send(data) # return None # # def unsubscribe(self, address): # data = { # "command": "unsubscribe", # "account": address, # } # self.send(data) # return None def subscribe(self, streams): request = Request(self, "subscribe") if streams is not None: request.message.streams = streams if isinstance(streams, list) else [streams] return request ##设置账号属性 def buildAccountSetTx(self,options): tx=Transaction(self) if not options: tx.tx_json.obj = Error('invalid options type') return tx if not ~Transaction.AccountSetTypes.index(options.type): tx.tx_json.type = Error('invalid account set type') return tx if options.type=='property': return self.__buildAccountSet(options, tx) elif options.type=='delegate': return self.__buildDelegateKeySet(options, tx) elif options.type=='signer': return self.__buildSignerSet(options.tx) tx.tx_json.msg=Error('build account set should not go here') return tx def __buildAccountSet(self,options,tx): src = options.source or options.fromnow or options.account set_flag = options.set_flag or options.set clear_flag = options.clear_flag or options.clear if not utils.isValidAmount(): pass tx.tx_json.TransactionType = 'AccountSet' tx.tx_json.Account = src SetClearFlags = Transaction.set_clear_flags.AccountSet if (set_flag and (set_flag = __prepareFlag(set_flag,SetClearFlags))):