You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
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'
|
|
#commentPath='/home/hua/下载/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 = '{commentPath}/{fileName}.zip'.format(commentPath=commentPath,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()
|
|
|