Ejemplo n.º 1
0
 def get_client_transport(self, service):
     host, port = service.get_host_port()
     print(host, port)
     transport = TTransport.TFramedTransport(TSocket.TSocket(host, port))
     protocol = TBinaryProtocol.TBinaryProtocol(transport)
     transport.open()
     return LucidaService.Client(protocol), transport
Ejemplo n.º 2
0
def threaded_function():
    handler = LucidaServiceHandler()
    processor = LucidaService.Processor(handler)
    transport = TSocket.TServerSocket(port=8080)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    server = TNonblockingServer.TNonblockingServer(processor, transport, pfactory, pfactory)
    print 'CMD at', str(8080)
    server.serve()
                message = parsed_json['message']
                result = "Error using API, " + message
                return result
            if 'weather' in parsed_json and 'main' in parsed_json and 'name' in parsed_json:
                weather = parsed_json['weather'][0]['description']
                temp = parsed_json['main']['temp']
                city = parsed_json['name']
                # if city in input_data:
                result = 'Current weather in %s is %s, temperature is %s Fahrenheit' % (
                    city, weather, temp)
                print 'From Open Weather Map: %s' % result
            f.close()
        except IOError as err:
            if 401 in err:
                result = 'Unauthorized Weather API keys'
            else:
                result = 'Weather Service is broken!'
        return result


# Set handler to our implementation
handler = WeatherHandler()
processor = LucidaService.Processor(handler)
transport = TSocket.TServerSocket(port=PORT)
tfactory = TTransport.TFramedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

print 'WE at port  %d' % PORT
server.serve()
Ejemplo n.º 4
0
from lucidatypes.ttypes import QueryInput, QuerySpec
from lucidaservice import LucidaService

from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

# Setup a template input query
LUCID = "Clinc"
query_input_data = "I want a happy song."
query_input = QueryInput(type="query", data=[query_input_data])
query_spec = QuerySpec(content=[query_input])

try:
    transport = TSocket.TSocket('localhost', PORT)
    transport = TTransport.TFramedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = LucidaService.Client(protocol)
    transport.open()

    # Test the server
    print "----Test client----\nQuery: ", query_input_data
    msg = client.infer(LUCID, query_spec)
    print "------Result:------\n", msg

    transport.close()

except Thrift.TException, ex:
    print "%s" % (ex.message)