Пример #1
0
    def setUp(self):
        try:
            self.transport = TSocket.TSocket('localhost', 9090)

            # Buffering is critical. Raw sockets are very slow
            self.transport = TTransport.TBufferedTransport(self.transport)

            # Wrap in a protocol
            self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)

            # Create a client to use the protocol encoder
            self.client = Twitter.Client(self.protocol)

            # Connect!
            self.transport.open()

        except Thrift.TException, tx:
            print '%s' % (tx.message)
Пример #2
0
def invoke_method():
    try:
        transport = TSocket.TSocket(server, port)
        transport = TTransport.TBufferedTransport(transport)

        protocol = TBinaryProtocol.TBinaryProtocol(transport)
        client = Twitter.Client(protocol)

        transport.open()

        if method == "createUser":
            client.createUser(parameters[0])
            print 'None'

        elif method == "subscribe":
            client.subscribe(parameters[0], parameters[1])
            print 'None'

        elif method == "unsubscribe":
            client.unsubscribe(parameters[0], parameters[1])
            print 'None'

        elif method == "post":
            client.post(parameters[0], parameters[1])
            print 'None'

        elif method == "readTweetsByUser":
            l = client.readTweetsByUser(parameters[0], int(parameters[1]))
            print l

        elif method == "readTweetsBySubscription":
            l = client.readTweetsBySubscription(parameters[0],
                                                int(parameters[1]))
            print l

        elif method == "star":
            client.star(parameters[0], long(parameters[1]))
            print 'None'

        transport.close()

    except AlreadyExistsException, userx:
        print 'AlreadyExistesException for user ' + parameters[0]
        return 'AlreadyExistsException'
def do_RPC(service, handle, value=None):
    try:
        transport = TSocket.TSocket(server, 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 = Twitter.Client(protocol)
        # Connect!
        transport.open()

        ## supported services
        if service == "createUser":
            return client.createUser(handle)

        elif service == "subscribe":
            return client.subscribe(handle, value)

        elif service == "unsubscribe":
            return client.unsubscribe(handle, value)

        elif service == "post":
            return client.post(handle, value)

        elif service == "readTweetsByUser":
            return client.readTweetsByUser(handle, int(value))

        elif service == "readTweetsBySubscription":
            return client.readTweetsBySubscription(handle, int(value))

        elif service == "star":
            return client.star(handle, int(value))

        # Close!
        transport.close()
    ## supported exceptions
    except AlreadyExistsException, userx:
        return 'AlreadyExistsException'
Пример #4
0
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

try:
    transport = TSocket.TSocket('localhost', 9090)

    # 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 = Twitter.Client(protocol)

    # Connect!
    transport.open()

    client.ping()
    client.createUser('jwchen')
    client.createUser('mqin')
    client.createUser('porter')
    #client.createUser('jwchen')
    client.subscribe('mqin', 'jwchen')
    client.subscribe('mqin', 'porter')
    #client.printSubscribeName('mqin')
    #client.unsubscribe('mqin','jwchen')
    #client.printSubscribeName('mqin')
Пример #5
0
 def setUp(self):
     self.transport = TSocket.TSocket('169.228.66.135', '6508')
     self.transport = TTransport.TBufferedTransport(self.transport)
     protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
     self.client = Twitter.Client(protocol)
     self.transport.open()