def main(): p = sys.argv[1] # Make socket transport = TSocket.TSocket('localhost', p) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Graph.Client(protocol) # Connect! transport.open() client.ping() f = [ client.ping, client.add_upd_vertex, client.add_upd_edge, client.get_vertex, client.get_edge, client.del_vertex, client.del_edge, client.list_edges, client.list_vertices, client.list_neighbors, client.shortest_path ] # print(client.add_upd_vertex(1,1,"1",1)) # print(client.add_upd_vertex(2,2,"2",2)) # print(client.add_upd_vertex(3,3,"3",3)) # print(client.add_upd_vertex(4,4,"4",4)) # print(client.add_upd_vertex(5,5,"5",5)) # print(client.add_upd_edge(2,1,100.0,True)) # print(client.add_upd_edge(1,3,200.0,False)) # print(client.add_upd_edge(2,4,100.0,True)) # print(client.add_upd_edge(3,4,100.0,False)) # print(client.add_upd_edge(3,5,500.0,False)) while 1: choice = input(opt) choice = int(choice) if choice == 0: client.ping() continue args = input(str(signature(f[choice])) + '\n') args = args.split() args[0] = int(args[0]) if len(args) > 1: args[1] = int(args[1]) if choice == 1: args[3] = float(args[3]) elif choice == 2: args[2] = float(args[2]) args[3] = bool(int(args[3])) try: print(f[choice](*args)) print('\n') except NotFound as e: print(e.dsc) # Close! transport.close()
def init_interface(self, port): transport = TSocket.TSocket('localhost', port) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Graph.Client(protocol) # Connect! transport.open() self.interfaces[port] = client
def main(): p = sys.argv[1] global client # Make socket transport = TSocket.TSocket('localhost', p) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Graph.Client(protocol) # Connect! transport.open() client.ping() print("FILMEBOOK") options = { 0: add_pessoa, 1: add_filme, 2: add_grupo, 3: add_aval, 4: pessoa_grupo, 5: filmes_pessoa, 6: filmes_grupo, 7: caminho, 8: filme_det } while 1: choice = input(opt) choice = int(choice) options[choice]() # Close! transport.close()
def main(): p = sys.argv[1] # Make socket transport = TSocket.TSocket('localhost', p) # Buffering is critical. Raw sockets are very slow transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = TBinaryProtocol.TBinaryProtocol(transport) # Create a client to use the protocol encoder client = Graph.Client(protocol) # Connect! transport.open() client.ping() print(client.add_upd_vertex(name_hash("Alice"), pessoa, "Alice", 0)) print(client.add_upd_vertex(name_hash("Bob"), pessoa, "Bob", 0)) print(client.add_upd_vertex(name_hash("Carla"), pessoa, "Carla", 0)) print(client.add_upd_vertex(name_hash("Dan"), pessoa, "Dan", 0)) print(client.add_upd_vertex(name_hash("Eve"), pessoa, "Eve", 0)) print( client.add_upd_vertex(name_hash("Blade Runner"), filme, "Blade Runner", 0)) print( client.add_upd_vertex(name_hash("Terminator 2"), filme, "Terminator 2", 0)) print( client.add_upd_vertex(name_hash("The Matrix"), filme, "The Matrix", 0)) print( client.add_upd_vertex(name_hash("Ex Machina"), filme, "Ex Machina", 0)) print(client.add_upd_vertex(name_hash("Her"), filme, "Her", 0)) print( client.add_upd_vertex(name_hash("Harrison Ford"), cast, "Harrison Ford", 0)) print( client.add_upd_vertex(name_hash("Arnold Schwarzenegger"), cast, "Arnold Schwarzenegger", 0)) print( client.add_upd_vertex(name_hash("Keanu Reeves"), cast, "Keanu Reeves", 0)) print( client.add_upd_vertex(name_hash("Domhnall Gleeson"), cast, "Domhnall Gleeson", 0)) print( client.add_upd_vertex(name_hash("Joaquin Phoenix"), cast, "Joaquin Phoenix", 0)) print(client.add_upd_vertex(name_hash("oldschool"), grupo, "oldschool", 0)) print(client.add_upd_vertex(name_hash("scifi"), grupo, "scifi", 0)) print( client.add_upd_edge(name_hash("Blade Runner"), name_hash("Harrison Ford"), cst, True)) print( client.add_upd_edge(name_hash("Terminator 2"), name_hash("Arnold Schwarzenegger"), cst, True)) print( client.add_upd_edge(name_hash("The Matrix"), name_hash("Keanu Reeves"), cst, True)) print( client.add_upd_edge(name_hash("Ex Machina"), name_hash("Domhnall Gleeson"), cst, True)) print( client.add_upd_edge(name_hash("Her"), name_hash("Joaquin Phoenix"), cst, True)) print( client.add_upd_edge(name_hash("Alice"), name_hash("Terminator 2"), 91.0, True)) print( client.add_upd_edge(name_hash("Alice"), name_hash("Ex Machina"), 79.0, True)) print( client.add_upd_edge(name_hash("Bob"), name_hash("The Matrix"), 90.0, True)) print(client.add_upd_edge(name_hash("Carla"), name_hash("Her"), 75.0, True)) print( client.add_upd_edge(name_hash("Dan"), name_hash("Blade Runner"), 75.0, True)) print( client.add_upd_edge(name_hash("Dan"), name_hash("Terminator 2"), 80.0, True)) print( client.add_upd_edge(name_hash("Dan"), name_hash("The Matrix"), 79.0, True)) print( client.add_upd_edge(name_hash("Eve"), name_hash("Ex Machina"), 60.0, True)) print(client.add_upd_edge(name_hash("scifi"), name_hash("Alice"), 0, False)) print(client.add_upd_edge(name_hash("scifi"), name_hash("Bob"), 0, False)) print(client.add_upd_edge(name_hash("scifi"), name_hash("Carla"), 0, False)) print(client.add_upd_edge(name_hash("scifi"), name_hash("Dan"), 0, False)) print( client.add_upd_edge(name_hash("oldschool"), name_hash("Alice"), 0, False)) print( client.add_upd_edge(name_hash("oldschool"), name_hash("Dan"), 0, False)) # Close! transport.close()