Example #1
0
def main():
    n = 100000

    print("binary protocol struct benchmark for {} times:".format(n))
    encode(n)
    decode(n)

    print("\ncybin protocol struct benchmark for {} times:".format(n))
    encode(n, TCyBinaryProtocolFactory())
    decode(n, TCyBinaryProtocolFactory())
Example #2
0
def main():
    with client_context(
            sc_thrift.SCService,
            '127.0.0.1',
            6000,
            proto_factory=TCyBinaryProtocolFactory(),
            trans_factory=TCyBufferedTransportFactory()) as context:
        client = Client(context)
        client.play()
def main():
    server = make_server(calc_thrift.Calculator,
                         Dispatcher(),
                         '127.0.0.1',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory(),
                         trans_factory=TCyBufferedTransportFactory())
    print("serving...")
    server.serve()
Example #4
0
def main():
    with client_context(calc_thrift.Calculator,
                        '127.0.0.1',
                        6000,
                        proto_factory=TCyBinaryProtocolFactory(),
                        trans_factory=TCyBufferedTransportFactory()) as cal:
        a = cal.mult(5, 2)
        b = cal.sub(7, 3)
        c = cal.sub(6, 4)
        d = cal.mult(b, 10)
        e = cal.add(a, d)
        f = cal.div(e, c)
        print(f)
Example #5
0
def main():
    sample_payload = "CwFAAAAAAi9pCwBkAAAACTEyNy4wLjAuMQoAyAAAAVjbnjdoC3ppAAAAQWlnbHU6Y29tLnNub3dwbG93YW5hbHl0aWNzLnNub3dwbG93L0NvbGxlY3RvclBheWxvYWQvdGhyaWZ0LzEtMC0wCwFKAAABaHN0bT0xNDgxMTUzMzI5MDAwJmU9cHYmdXJsPWh0dHAlM0ElMkYlMkZzbm93Zmxha2UtYW5hbHl0aWNzLmNvbSZ0dj1qcy0yLjYuMCZ0bmE9anMtMy42LjAmYWlkPXNub3dmbGFrZSZwPXdlYiZ0ej1BdXN0cmFsaWElMkZTeWRuZXkmbGFuZz1lbi1BVSZjcz1VVEYtOCZyZXM9MzYweDY0MCZjZD0zMiZjb29raWU9MSZlaWQ9YzI1OWMyNWUtZjk0Yi00ZDJjLWExMWMtMGQyNzhjMmU2ZDFhJmR0bT0xNDc5OTI3ODU3M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Rm9yOiAxMjcuMC4wLjEAAAAVWC1Gb3J3YXJkZWQtUG9ydDogNDQzAAAAGFgtRm9yd2FyZGVkLVByb3RvOiBodHRwcwAAABZDb25uZWN0aW9uOiBrZWVwLWFsaXZlAA=="
    decoded_payload = base64.b64decode(sample_payload)
    # print(decoded_payload)

    collector = thriftpy2.load("collector-payload.thrift")
    collector_payload = collector.CollectorPayload()
    raw_payload = deserialize(collector_payload, decoded_payload,
                              TCyBinaryProtocolFactory())
    print(raw_payload)

    querystring = raw_payload.querystring
    network_userid = raw_payload.networkUserId
    print(network_userid)
    print(querystring)
 def get_protoco_factory(self):
     from thriftpy2.protocol import TCyBinaryProtocolFactory
     return TCyBinaryProtocolFactory().get_protocol
Example #7
0
    def fetch_all_works(self, uid):
        return json.dumps(kol.fetch_all_video(uid))

    def checkout_user_agent(self):
        return kol.checkout_user_agent()


if sys.platform == 'win32':
    kol_thrift = thriftpy.load(os.path.join(
        PRO_DIR, '.\\dolphin\\service\\douyin\\data\\kol_thrift.thrift'),
                               module_name='kol_thrift_thrift')
else:
    kol_thrift = thriftpy.load(os.path.join(
        PRO_DIR, './dolphin/service/douyin/data/kol_thrift.thrift'),
                               module_name='kol_thrift_thrift')

app = TProcessor(kol_thrift.KolServer, KolDispatcher())
# server = TProcessor(kol_thrift.KolServer, KolDispatcher())
#
if __name__ == '__main__':
    server = make_server(kol_thrift.KolServer,
                         KolDispatcher(),
                         '0.0.0.0',
                         6000,
                         proto_factory=TCyBinaryProtocolFactory(),
                         trans_factory=TCyBufferedTransportFactory())
    server.serve()

    # gunicorn_thrift dolphin.service.douyin.kolserver:app -k thriftpy_sync -b 0.0.0.0:6000 -w 4 --thrift-protocol-factory thriftpy.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy.transport:TCyBufferedTransportFactory --thrift-client-timeout=5
    # gunicorn_thrift dolphin.service.douyin.kolserver:app --bind 0.0.0.0:7000 -w 10 -k thriftpy_gevent  --timeout 10  --thrift-protocol-factory thriftpy2.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy2.transport:TCyBufferedTransportFactory --error-logfile aa.log -D -p douyin_server.pid
Example #8
0
        try:
            sig, dytk, ua = kol.get_sig_dytk(uid, dytk=dytk, tac=tac)
            r = {
                'sig': sig,
                'dytk': dytk,
                'ua': ua
            }
        except BaseException as e:
            import traceback
            traceback.print_exc()
            return json.dumps({'msg': str(e)})
        return json.dumps(r)

    def checkout_user_agent(self):
        return kol.checkout_user_agent()


if sys.platform == 'win32':
    kol_thrift = thriftpy.load(os.path.join(PRO_DIR, '.\\dolphin\\service\\douyin\\data\\kol_thrift.thrift'), module_name='kol_thrift_thrift')
else:
    kol_thrift = thriftpy.load(os.path.join(PRO_DIR, './dolphin/service/douyin/data/kol_thrift.thrift'), module_name='kol_thrift_thrift')

app = TProcessor(kol_thrift.KolServer, KolDispatcher())
# server = TProcessor(kol_thrift.KolServer, KolDispatcher())
#
if __name__ == '__main__':
    server = make_server(kol_thrift.KolServer, KolDispatcher(), '0.0.0.0', 7000, proto_factory=TCyBinaryProtocolFactory(), trans_factory=TCyBufferedTransportFactory())
    server.serve()

    # gunicorn_thrift dolphin.service.douyin.kolserver:app -k thriftpy_sync -b 0.0.0.0:6000 -w 4 --thrift-protocol-factory thriftpy.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy.transport:TCyBufferedTransportFactory --thrift-client-timeout=5
    # gunicorn_thrift dolphin.service.douyin.kolserver:app --bind 0.0.0.0:7000 -w 10 -k thriftpy_gevent  --timeout 10  --thrift-protocol-factory thriftpy2.protocol:TCyBinaryProtocolFactory --thrift-transport-factory thriftpy2.transport:TCyBufferedTransportFactory --error-logfile aa.log -D -p douyin_server.pid
Example #9
0
def consume_stream(stream_name, region, enriched, limit, interval, max_records, pretty):
    if limit < 2:
        limit = 2

    if interval < .5:
        interval = .5

    print_banner(stream_name, region, interval)

    response = client.describe_stream(StreamName=stream_name)

    shard_it = client.get_shard_iterator(StreamName=stream_name,
                                         ShardId=response['StreamDescription']['Shards'][0]['ShardId'],
                                         ShardIteratorType='LATEST')["ShardIterator"]

    output = client.get_records(ShardIterator=shard_it, Limit=2)

    count = 0
    while 'NextShardIterator' in output:
        output = client.get_records(ShardIterator=output['NextShardIterator'], Limit=limit)
        records = output.get('Records')
        if records:
            for record in records:
                if count > max_records:
                    sys.exit(0)
                else:
                    payload = None
                    if enriched:
                        try:
                            payload = snowplow_analytics_sdk.event_transformer.transform(record.get('Data').decode("utf-8"))
                        except():
                            print("An exception occurred when converting an enriched event.")
                    else:
                        try:
                            payload = vars(deserialize(collector_payload, record.get('Data'), TCyBinaryProtocolFactory()))
                            payload['body'] = parse.parse_qs(payload.get('body'))
                        except():
                            print("An exception occurred when converting an enriched event.")

                    record['Data'] = payload

                    result = json.dumps(record, default=serializer, ensure_ascii=False)
                    pprint(result) if pretty else print(result)

                    if max_records > 0:
                        count += 1

        time.sleep(interval)