parent
06a5a453f4
commit
f0e5adb105
@ -0,0 +1,660 @@ |
||||
# |
||||
# Autogenerated by Thrift Compiler (0.11.0) |
||||
# |
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
||||
# |
||||
# options string: py |
||||
# |
||||
|
||||
from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException |
||||
from thrift.protocol.TProtocol import TProtocolException |
||||
from thrift.TRecursive import fix_spec |
||||
|
||||
import sys |
||||
import logging |
||||
from .ttypes import * |
||||
from thrift.Thrift import TProcessor |
||||
from thrift.transport import TTransport |
||||
all_structs = [] |
||||
|
||||
|
||||
class Iface(object): |
||||
def commentSum(self, cid): |
||||
""" |
||||
查询单个cid弹幕数 |
||||
|
||||
|
||||
Parameters: |
||||
- cid |
||||
""" |
||||
pass |
||||
|
||||
def commentSumList(self, cids): |
||||
""" |
||||
* 批量查询多个cid弹幕数 |
||||
* |
||||
|
||||
Parameters: |
||||
- cids |
||||
""" |
||||
pass |
||||
|
||||
def download(self, cids, fileName): |
||||
""" |
||||
* 批量下载弹幕 |
||||
* |
||||
|
||||
Parameters: |
||||
- cids |
||||
- fileName |
||||
""" |
||||
pass |
||||
|
||||
|
||||
class Client(Iface): |
||||
def __init__(self, iprot, oprot=None): |
||||
self._iprot = self._oprot = iprot |
||||
if oprot is not None: |
||||
self._oprot = oprot |
||||
self._seqid = 0 |
||||
|
||||
def commentSum(self, cid): |
||||
""" |
||||
查询单个cid弹幕数 |
||||
|
||||
|
||||
Parameters: |
||||
- cid |
||||
""" |
||||
self.send_commentSum(cid) |
||||
return self.recv_commentSum() |
||||
|
||||
def send_commentSum(self, cid): |
||||
self._oprot.writeMessageBegin('commentSum', TMessageType.CALL, self._seqid) |
||||
args = commentSum_args() |
||||
args.cid = cid |
||||
args.write(self._oprot) |
||||
self._oprot.writeMessageEnd() |
||||
self._oprot.trans.flush() |
||||
|
||||
def recv_commentSum(self): |
||||
iprot = self._iprot |
||||
(fname, mtype, rseqid) = iprot.readMessageBegin() |
||||
if mtype == TMessageType.EXCEPTION: |
||||
x = TApplicationException() |
||||
x.read(iprot) |
||||
iprot.readMessageEnd() |
||||
raise x |
||||
result = commentSum_result() |
||||
result.read(iprot) |
||||
iprot.readMessageEnd() |
||||
if result.success is not None: |
||||
return result.success |
||||
raise TApplicationException(TApplicationException.MISSING_RESULT, "commentSum failed: unknown result") |
||||
|
||||
def commentSumList(self, cids): |
||||
""" |
||||
* 批量查询多个cid弹幕数 |
||||
* |
||||
|
||||
Parameters: |
||||
- cids |
||||
""" |
||||
self.send_commentSumList(cids) |
||||
return self.recv_commentSumList() |
||||
|
||||
def send_commentSumList(self, cids): |
||||
self._oprot.writeMessageBegin('commentSumList', TMessageType.CALL, self._seqid) |
||||
args = commentSumList_args() |
||||
args.cids = cids |
||||
args.write(self._oprot) |
||||
self._oprot.writeMessageEnd() |
||||
self._oprot.trans.flush() |
||||
|
||||
def recv_commentSumList(self): |
||||
iprot = self._iprot |
||||
(fname, mtype, rseqid) = iprot.readMessageBegin() |
||||
if mtype == TMessageType.EXCEPTION: |
||||
x = TApplicationException() |
||||
x.read(iprot) |
||||
iprot.readMessageEnd() |
||||
raise x |
||||
result = commentSumList_result() |
||||
result.read(iprot) |
||||
iprot.readMessageEnd() |
||||
if result.success is not None: |
||||
return result.success |
||||
raise TApplicationException(TApplicationException.MISSING_RESULT, "commentSumList failed: unknown result") |
||||
|
||||
def download(self, cids, fileName): |
||||
""" |
||||
* 批量下载弹幕 |
||||
* |
||||
|
||||
Parameters: |
||||
- cids |
||||
- fileName |
||||
""" |
||||
self.send_download(cids, fileName) |
||||
return self.recv_download() |
||||
|
||||
def send_download(self, cids, fileName): |
||||
self._oprot.writeMessageBegin('download', TMessageType.CALL, self._seqid) |
||||
args = download_args() |
||||
args.cids = cids |
||||
args.fileName = fileName |
||||
args.write(self._oprot) |
||||
self._oprot.writeMessageEnd() |
||||
self._oprot.trans.flush() |
||||
|
||||
def recv_download(self): |
||||
iprot = self._iprot |
||||
(fname, mtype, rseqid) = iprot.readMessageBegin() |
||||
if mtype == TMessageType.EXCEPTION: |
||||
x = TApplicationException() |
||||
x.read(iprot) |
||||
iprot.readMessageEnd() |
||||
raise x |
||||
result = download_result() |
||||
result.read(iprot) |
||||
iprot.readMessageEnd() |
||||
if result.success is not None: |
||||
return result.success |
||||
raise TApplicationException(TApplicationException.MISSING_RESULT, "download failed: unknown result") |
||||
|
||||
|
||||
class Processor(Iface, TProcessor): |
||||
def __init__(self, handler): |
||||
self._handler = handler |
||||
self._processMap = {} |
||||
self._processMap["commentSum"] = Processor.process_commentSum |
||||
self._processMap["commentSumList"] = Processor.process_commentSumList |
||||
self._processMap["download"] = Processor.process_download |
||||
|
||||
def process(self, iprot, oprot): |
||||
(name, type, seqid) = iprot.readMessageBegin() |
||||
if name not in self._processMap: |
||||
iprot.skip(TType.STRUCT) |
||||
iprot.readMessageEnd() |
||||
x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) |
||||
oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) |
||||
x.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
return |
||||
else: |
||||
self._processMap[name](self, seqid, iprot, oprot) |
||||
return True |
||||
|
||||
def process_commentSum(self, seqid, iprot, oprot): |
||||
args = commentSum_args() |
||||
args.read(iprot) |
||||
iprot.readMessageEnd() |
||||
result = commentSum_result() |
||||
try: |
||||
result.success = self._handler.commentSum(args.cid) |
||||
msg_type = TMessageType.REPLY |
||||
except TTransport.TTransportException: |
||||
raise |
||||
except TApplicationException as ex: |
||||
logging.exception('TApplication exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = ex |
||||
except Exception: |
||||
logging.exception('Unexpected exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') |
||||
oprot.writeMessageBegin("commentSum", msg_type, seqid) |
||||
result.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
|
||||
def process_commentSumList(self, seqid, iprot, oprot): |
||||
args = commentSumList_args() |
||||
args.read(iprot) |
||||
iprot.readMessageEnd() |
||||
result = commentSumList_result() |
||||
try: |
||||
result.success = self._handler.commentSumList(args.cids) |
||||
msg_type = TMessageType.REPLY |
||||
except TTransport.TTransportException: |
||||
raise |
||||
except TApplicationException as ex: |
||||
logging.exception('TApplication exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = ex |
||||
except Exception: |
||||
logging.exception('Unexpected exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') |
||||
oprot.writeMessageBegin("commentSumList", msg_type, seqid) |
||||
result.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
|
||||
def process_download(self, seqid, iprot, oprot): |
||||
args = download_args() |
||||
args.read(iprot) |
||||
iprot.readMessageEnd() |
||||
result = download_result() |
||||
try: |
||||
result.success = self._handler.download(args.cids, args.fileName) |
||||
msg_type = TMessageType.REPLY |
||||
except TTransport.TTransportException: |
||||
raise |
||||
except TApplicationException as ex: |
||||
logging.exception('TApplication exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = ex |
||||
except Exception: |
||||
logging.exception('Unexpected exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') |
||||
oprot.writeMessageBegin("download", msg_type, seqid) |
||||
result.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
|
||||
# HELPER FUNCTIONS AND STRUCTURES |
||||
|
||||
|
||||
class commentSum_args(object): |
||||
""" |
||||
Attributes: |
||||
- cid |
||||
""" |
||||
|
||||
|
||||
def __init__(self, cid=None,): |
||||
self.cid = cid |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 1: |
||||
if ftype == TType.I32: |
||||
self.cid = iprot.readI32() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('commentSum_args') |
||||
if self.cid is not None: |
||||
oprot.writeFieldBegin('cid', TType.I32, 1) |
||||
oprot.writeI32(self.cid) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(commentSum_args) |
||||
commentSum_args.thrift_spec = ( |
||||
None, # 0 |
||||
(1, TType.I32, 'cid', None, None, ), # 1 |
||||
) |
||||
|
||||
|
||||
class commentSum_result(object): |
||||
""" |
||||
Attributes: |
||||
- success |
||||
""" |
||||
|
||||
|
||||
def __init__(self, success=None,): |
||||
self.success = success |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 0: |
||||
if ftype == TType.I32: |
||||
self.success = iprot.readI32() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('commentSum_result') |
||||
if self.success is not None: |
||||
oprot.writeFieldBegin('success', TType.I32, 0) |
||||
oprot.writeI32(self.success) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(commentSum_result) |
||||
commentSum_result.thrift_spec = ( |
||||
(0, TType.I32, 'success', None, None, ), # 0 |
||||
) |
||||
|
||||
|
||||
class commentSumList_args(object): |
||||
""" |
||||
Attributes: |
||||
- cids |
||||
""" |
||||
|
||||
|
||||
def __init__(self, cids=None,): |
||||
self.cids = cids |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 1: |
||||
if ftype == TType.LIST: |
||||
self.cids = [] |
||||
(_etype3, _size0) = iprot.readListBegin() |
||||
for _i4 in range(_size0): |
||||
_elem5 = iprot.readI32() |
||||
self.cids.append(_elem5) |
||||
iprot.readListEnd() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('commentSumList_args') |
||||
if self.cids is not None: |
||||
oprot.writeFieldBegin('cids', TType.LIST, 1) |
||||
oprot.writeListBegin(TType.I32, len(self.cids)) |
||||
for iter6 in self.cids: |
||||
oprot.writeI32(iter6) |
||||
oprot.writeListEnd() |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(commentSumList_args) |
||||
commentSumList_args.thrift_spec = ( |
||||
None, # 0 |
||||
(1, TType.LIST, 'cids', (TType.I32, None, False), None, ), # 1 |
||||
) |
||||
|
||||
|
||||
class commentSumList_result(object): |
||||
""" |
||||
Attributes: |
||||
- success |
||||
""" |
||||
|
||||
|
||||
def __init__(self, success=None,): |
||||
self.success = success |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 0: |
||||
if ftype == TType.LIST: |
||||
self.success = [] |
||||
(_etype10, _size7) = iprot.readListBegin() |
||||
for _i11 in range(_size7): |
||||
_elem12 = iprot.readI32() |
||||
self.success.append(_elem12) |
||||
iprot.readListEnd() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('commentSumList_result') |
||||
if self.success is not None: |
||||
oprot.writeFieldBegin('success', TType.LIST, 0) |
||||
oprot.writeListBegin(TType.I32, len(self.success)) |
||||
for iter13 in self.success: |
||||
oprot.writeI32(iter13) |
||||
oprot.writeListEnd() |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(commentSumList_result) |
||||
commentSumList_result.thrift_spec = ( |
||||
(0, TType.LIST, 'success', (TType.I32, None, False), None, ), # 0 |
||||
) |
||||
|
||||
|
||||
class download_args(object): |
||||
""" |
||||
Attributes: |
||||
- cids |
||||
- fileName |
||||
""" |
||||
|
||||
|
||||
def __init__(self, cids=None, fileName=None,): |
||||
self.cids = cids |
||||
self.fileName = fileName |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 1: |
||||
if ftype == TType.LIST: |
||||
self.cids = [] |
||||
(_etype17, _size14) = iprot.readListBegin() |
||||
for _i18 in range(_size14): |
||||
_elem19 = iprot.readI32() |
||||
self.cids.append(_elem19) |
||||
iprot.readListEnd() |
||||
else: |
||||
iprot.skip(ftype) |
||||
elif fid == 2: |
||||
if ftype == TType.STRING: |
||||
self.fileName = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('download_args') |
||||
if self.cids is not None: |
||||
oprot.writeFieldBegin('cids', TType.LIST, 1) |
||||
oprot.writeListBegin(TType.I32, len(self.cids)) |
||||
for iter20 in self.cids: |
||||
oprot.writeI32(iter20) |
||||
oprot.writeListEnd() |
||||
oprot.writeFieldEnd() |
||||
if self.fileName is not None: |
||||
oprot.writeFieldBegin('fileName', TType.STRING, 2) |
||||
oprot.writeString(self.fileName.encode('utf-8') if sys.version_info[0] == 2 else self.fileName) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(download_args) |
||||
download_args.thrift_spec = ( |
||||
None, # 0 |
||||
(1, TType.LIST, 'cids', (TType.I32, None, False), None, ), # 1 |
||||
(2, TType.STRING, 'fileName', 'UTF8', None, ), # 2 |
||||
) |
||||
|
||||
|
||||
class download_result(object): |
||||
""" |
||||
Attributes: |
||||
- success |
||||
""" |
||||
|
||||
|
||||
def __init__(self, success=None,): |
||||
self.success = success |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 0: |
||||
if ftype == TType.STRING: |
||||
self.success = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('download_result') |
||||
if self.success is not None: |
||||
oprot.writeFieldBegin('success', TType.STRING, 0) |
||||
oprot.writeString(self.success.encode('utf-8') if sys.version_info[0] == 2 else self.success) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(download_result) |
||||
download_result.thrift_spec = ( |
||||
(0, TType.STRING, 'success', 'UTF8', None, ), # 0 |
||||
) |
||||
fix_spec(all_structs) |
||||
del all_structs |
||||
|
@ -0,0 +1,48 @@ |
||||
import os |
||||
import sys |
||||
|
||||
from thrift.server.TNonblockingServer import TNonblockingServer |
||||
from thrift.transport import TSocket |
||||
|
||||
sys.path.append('/root/PixivSearch') |
||||
from PixivSearch.util import Util |
||||
from PixivSearch.dao.Comment import xml, downloadXml |
||||
from PixivSearch.thrift.QueryComment import QueryComment |
||||
from PixivSearch.thrift.QueryComment.QueryComment import Iface |
||||
|
||||
commentPath = '/root/PixivSearch/PixivSearch/thrift/tmpFile/comment' |
||||
|
||||
|
||||
class Server(Iface): |
||||
def commentSumList(self, cids): |
||||
result = [] |
||||
for cid in cids: |
||||
comment_selector = xml('https://comment.bilibili.com/{cid}.xml'.format(cid=cid)) |
||||
length = len(comment_selector.xpath('//i//d/text()')) |
||||
print('cid:{cid},弹幕数:{length}'.format(cid=cid, length=length)) |
||||
result.append(length) |
||||
return result |
||||
|
||||
def commentSum(self, cid): |
||||
return self.commentSumList([cid])[0]; |
||||
|
||||
def download(self, cids, fileName): |
||||
path = '{commentPath}/{fileName}'.format(commentPath=commentPath, fileName=fileName) |
||||
for cid in cids: |
||||
downloadXml(path, cid, |
||||
histroy=False) |
||||
zipFile = '{path}/{fileName}.zip'.format(path=path,fileName=fileName) |
||||
print(zipFile) |
||||
Util.zip(path, zipFile) |
||||
if os.path.isfile(zipFile): |
||||
print('压缩包成功生成到{zipFile}'.format(zipFile=zipFile)) |
||||
return zipFile |
||||
else: |
||||
return None |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
socket = TSocket.TServerSocket(port=2233) |
||||
processor = QueryComment.Processor(Server()) |
||||
server = TNonblockingServer(processor, socket) |
||||
server.serve() |
@ -0,0 +1 @@ |
||||
__all__ = ['ttypes', 'constants', 'QueryComment'] |
@ -0,0 +1,18 @@ |
||||
# |
||||
# Autogenerated by Thrift Compiler (0.11.0) |
||||
# |
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
||||
# |
||||
# options string: py |
||||
# |
||||
|
||||
from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException |
||||
from thrift.protocol.TProtocol import TProtocolException |
||||
from thrift.TRecursive import fix_spec |
||||
|
||||
import sys |
||||
|
||||
from thrift.transport import TTransport |
||||
all_structs = [] |
||||
fix_spec(all_structs) |
||||
del all_structs |
@ -1,30 +0,0 @@ |
||||
import sys |
||||
|
||||
from thrift.server.TNonblockingServer import TNonblockingServer |
||||
from thrift.transport import TSocket |
||||
|
||||
sys.path.append('/root/PixivSearch') |
||||
from PixivSearch.thrift.TestQry import TestQry |
||||
from PixivSearch.thrift.TestQry.ttypes import QryResult |
||||
|
||||
|
||||
class QueryImpl(TestQry.Iface): |
||||
|
||||
def qryTest(self, qryCode): |
||||
result = QryResult() |
||||
if qryCode == 1: |
||||
result.code = 1 |
||||
result.msg = 'success' |
||||
|
||||
else: |
||||
result.code = 0 |
||||
result.msg = 'fail' |
||||
return result |
||||
|
||||
|
||||
if __name__ == '__main__': |
||||
socket = TSocket.TServerSocket(port=2233) |
||||
processor = TestQry.Processor(QueryImpl()) |
||||
server = TNonblockingServer(processor, socket) |
||||
|
||||
server.serve() |
@ -1,245 +0,0 @@ |
||||
# |
||||
# Autogenerated by Thrift Compiler (0.11.0) |
||||
# |
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
||||
# |
||||
# options string: py |
||||
# |
||||
import logging |
||||
|
||||
from thrift.TRecursive import fix_spec |
||||
from thrift.Thrift import TProcessor |
||||
from thrift.Thrift import TType, TMessageType, TApplicationException |
||||
from thrift.transport import TTransport |
||||
|
||||
from PixivSearch.thrift.TestQry.ttypes import QryResult |
||||
|
||||
all_structs = [] |
||||
|
||||
class Iface(object): |
||||
def qryTest(self, qryCode): |
||||
""" |
||||
测试查询接口,当qryCode值为1时返回"成功"的响应信息,qryCode值为其他值时返回"失败"的响应信息 |
||||
@param qryCode测试参数 |
||||
|
||||
Parameters: |
||||
- qryCode |
||||
""" |
||||
pass |
||||
|
||||
|
||||
class Client(Iface): |
||||
def __init__(self, iprot, oprot=None): |
||||
self._iprot = self._oprot = iprot |
||||
if oprot is not None: |
||||
self._oprot = oprot |
||||
self._seqid = 0 |
||||
|
||||
def qryTest(self, qryCode): |
||||
""" |
||||
测试查询接口,当qryCode值为1时返回"成功"的响应信息,qryCode值为其他值时返回"失败"的响应信息 |
||||
@param qryCode测试参数 |
||||
|
||||
Parameters: |
||||
- qryCode |
||||
""" |
||||
self.send_qryTest(qryCode) |
||||
return self.recv_qryTest() |
||||
|
||||
def send_qryTest(self, qryCode): |
||||
self._oprot.writeMessageBegin('qryTest', TMessageType.CALL, self._seqid) |
||||
args = qryTest_args() |
||||
args.qryCode = qryCode |
||||
args.write(self._oprot) |
||||
self._oprot.writeMessageEnd() |
||||
self._oprot.trans.flush() |
||||
|
||||
def recv_qryTest(self): |
||||
iprot = self._iprot |
||||
(fname, mtype, rseqid) = iprot.readMessageBegin() |
||||
if mtype == TMessageType.EXCEPTION: |
||||
x = TApplicationException() |
||||
x.read(iprot) |
||||
iprot.readMessageEnd() |
||||
raise x |
||||
result = qryTest_result() |
||||
result.read(iprot) |
||||
iprot.readMessageEnd() |
||||
if result.success is not None: |
||||
return result.success |
||||
raise TApplicationException(TApplicationException.MISSING_RESULT, "qryTest failed: unknown result") |
||||
|
||||
|
||||
class Processor(Iface, TProcessor): |
||||
def __init__(self, handler): |
||||
self._handler = handler |
||||
self._processMap = {} |
||||
self._processMap["qryTest"] = Processor.process_qryTest |
||||
|
||||
def process(self, iprot, oprot): |
||||
(name, type, seqid) = iprot.readMessageBegin() |
||||
if name not in self._processMap: |
||||
iprot.skip(TType.STRUCT) |
||||
iprot.readMessageEnd() |
||||
x = TApplicationException(TApplicationException.UNKNOWN_METHOD, 'Unknown function %s' % (name)) |
||||
oprot.writeMessageBegin(name, TMessageType.EXCEPTION, seqid) |
||||
x.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
return |
||||
else: |
||||
self._processMap[name](self, seqid, iprot, oprot) |
||||
return True |
||||
|
||||
def process_qryTest(self, seqid, iprot, oprot): |
||||
args = qryTest_args() |
||||
args.read(iprot) |
||||
iprot.readMessageEnd() |
||||
result = qryTest_result() |
||||
try: |
||||
result.success = self._handler.qryTest(args.qryCode) |
||||
msg_type = TMessageType.REPLY |
||||
except TTransport.TTransportException: |
||||
raise |
||||
except TApplicationException as ex: |
||||
logging.exception('TApplication exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = ex |
||||
except Exception: |
||||
logging.exception('Unexpected exception in handler') |
||||
msg_type = TMessageType.EXCEPTION |
||||
result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') |
||||
oprot.writeMessageBegin("qryTest", msg_type, seqid) |
||||
result.write(oprot) |
||||
oprot.writeMessageEnd() |
||||
oprot.trans.flush() |
||||
|
||||
# HELPER FUNCTIONS AND STRUCTURES |
||||
|
||||
|
||||
class qryTest_args(object): |
||||
""" |
||||
Attributes: |
||||
- qryCode |
||||
""" |
||||
|
||||
|
||||
def __init__(self, qryCode=None,): |
||||
self.qryCode = qryCode |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 1: |
||||
if ftype == TType.I32: |
||||
self.qryCode = iprot.readI32() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('qryTest_args') |
||||
if self.qryCode is not None: |
||||
oprot.writeFieldBegin('qryCode', TType.I32, 1) |
||||
oprot.writeI32(self.qryCode) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(qryTest_args) |
||||
qryTest_args.thrift_spec = ( |
||||
None, # 0 |
||||
(1, TType.I32, 'qryCode', None, None, ), # 1 |
||||
) |
||||
|
||||
|
||||
class qryTest_result(object): |
||||
""" |
||||
Attributes: |
||||
- success |
||||
""" |
||||
|
||||
|
||||
def __init__(self, success=None,): |
||||
self.success = success |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 0: |
||||
if ftype == TType.STRUCT: |
||||
self.success = QryResult() |
||||
self.success.read(iprot) |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('qryTest_result') |
||||
if self.success is not None: |
||||
oprot.writeFieldBegin('success', TType.STRUCT, 0) |
||||
self.success.write(oprot) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(qryTest_result) |
||||
qryTest_result.thrift_spec = ( |
||||
(0, TType.STRUCT, 'success', [QryResult, None], None, ), # 0 |
||||
) |
||||
fix_spec(all_structs) |
||||
del all_structs |
||||
|
||||
|
||||
|
||||
|
@ -1 +0,0 @@ |
||||
__all__ = ['ttypes', 'constants', 'TestQry'] |
@ -1,91 +0,0 @@ |
||||
# |
||||
# Autogenerated by Thrift Compiler (0.11.0) |
||||
# |
||||
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING |
||||
# |
||||
# options string: py |
||||
# |
||||
|
||||
from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException |
||||
from thrift.protocol.TProtocol import TProtocolException |
||||
from thrift.TRecursive import fix_spec |
||||
|
||||
import sys |
||||
|
||||
from thrift.transport import TTransport |
||||
all_structs = [] |
||||
|
||||
|
||||
class QryResult(object): |
||||
""" |
||||
Attributes: |
||||
- code: 返回码, 1成功,0失败 |
||||
- msg: 响应信息 |
||||
""" |
||||
|
||||
|
||||
def __init__(self, code=None, msg=None,): |
||||
self.code = code |
||||
self.msg = msg |
||||
|
||||
def read(self, iprot): |
||||
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None: |
||||
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec]) |
||||
return |
||||
iprot.readStructBegin() |
||||
while True: |
||||
(fname, ftype, fid) = iprot.readFieldBegin() |
||||
if ftype == TType.STOP: |
||||
break |
||||
if fid == 1: |
||||
if ftype == TType.I32: |
||||
self.code = iprot.readI32() |
||||
else: |
||||
iprot.skip(ftype) |
||||
elif fid == 2: |
||||
if ftype == TType.STRING: |
||||
self.msg = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString() |
||||
else: |
||||
iprot.skip(ftype) |
||||
else: |
||||
iprot.skip(ftype) |
||||
iprot.readFieldEnd() |
||||
iprot.readStructEnd() |
||||
|
||||
def write(self, oprot): |
||||
if oprot._fast_encode is not None and self.thrift_spec is not None: |
||||
oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) |
||||
return |
||||
oprot.writeStructBegin('QryResult') |
||||
if self.code is not None: |
||||
oprot.writeFieldBegin('code', TType.I32, 1) |
||||
oprot.writeI32(self.code) |
||||
oprot.writeFieldEnd() |
||||
if self.msg is not None: |
||||
oprot.writeFieldBegin('msg', TType.STRING, 2) |
||||
oprot.writeString(self.msg.encode('utf-8') if sys.version_info[0] == 2 else self.msg) |
||||
oprot.writeFieldEnd() |
||||
oprot.writeFieldStop() |
||||
oprot.writeStructEnd() |
||||
|
||||
def validate(self): |
||||
return |
||||
|
||||
def __repr__(self): |
||||
L = ['%s=%r' % (key, value) |
||||
for key, value in self.__dict__.items()] |
||||
return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) |
||||
|
||||
def __eq__(self, other): |
||||
return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ |
||||
|
||||
def __ne__(self, other): |
||||
return not (self == other) |
||||
all_structs.append(QryResult) |
||||
QryResult.thrift_spec = ( |
||||
None, # 0 |
||||
(1, TType.I32, 'code', None, None, ), # 1 |
||||
(2, TType.STRING, 'msg', 'UTF8', None, ), # 2 |
||||
) |
||||
fix_spec(all_structs) |
||||
del all_structs |
@ -0,0 +1,10 @@ |
||||
import os |
||||
import zipfile |
||||
|
||||
|
||||
def zip(inputFile, outFile): |
||||
f = zipfile.ZipFile(outFile, 'w', zipfile.ZIP_DEFLATED) |
||||
for dirpath, dirnames, filenames in os.walk(inputFile): |
||||
for filename in filenames: |
||||
f.write(os.path.join(dirpath, filename), filename) |
||||
f.close() |
Loading…
Reference in new issue