This commit is contained in:
dylan 2022-11-04 18:30:00 +08:00
parent 8ebcd4786d
commit 06acf3c664
1 changed files with 362 additions and 347 deletions

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# 自动带图评价、追评、服务评价需电脑端CK # 自动带图评价、追评、服务评价需电脑端CK
# @Time : 2022/10/2 # @Time : 2022/11/4
# @Author : @qiu-lzsnmb and @Dimlitter @Dylan # @Author : @qiu-lzsnmb and @Dimlitter @Dylan
# @File : auto_comment.py # @File : auto_comment.py
# 多账号评价,异常处理
''' '''
new Env('自动评价'); new Env('自动评价');
8 8 2 10 * https://raw.githubusercontent.com/6dylan6/auto_comment/main/jd_comment.py 8 8 2 10 * https://raw.githubusercontent.com/6dylan6/auto_comment/main/jd_comment.py
@ -35,8 +36,6 @@ except:
from lxml import etree from lxml import etree
import requests import requests
import jdspider import jdspider
@ -165,6 +164,7 @@ def generation(pname, _class=0, _type=1, opts=None):
# 查询全部评价 # 查询全部评价
def all_evaluate(opts=None): def all_evaluate(opts=None):
try:
opts = opts or {} opts = opts or {}
N = {} N = {}
url = 'https://club.jd.com/myJdcomments/myJdcomment.action?' url = 'https://club.jd.com/myJdcomments/myJdcomment.action?'
@ -195,9 +195,12 @@ def all_evaluate(opts=None):
num = 0 num = 0
N[na] = int(num) N[na] = int(num)
return N return N
except Exception as e:
print (e)
# 评价晒单 # 评价晒单
def sunbw(N, opts=None): def sunbw(N, opts=None):
try:
opts = opts or {} opts = opts or {}
Order_data = [] Order_data = []
req_et = [] req_et = []
@ -339,10 +342,12 @@ def sunbw(N, opts=None):
idx += 1 idx += 1
N['待评价订单'] -= 1 N['待评价订单'] -= 1
return N return N
except Exception as e:
print (e)
# 追评 # 追评
def review(N, opts=None): def review(N, opts=None):
try:
opts = opts or {} opts = opts or {}
req_et = [] req_et = []
Order_data = [] Order_data = []
@ -425,10 +430,12 @@ def review(N, opts=None):
time.sleep(REVIEW_SLEEP_SEC) time.sleep(REVIEW_SLEEP_SEC)
N['待追评'] -= 1 N['待追评'] -= 1
return N return N
except Exception as e:
print (e)
# 服务评价 # 服务评价
def Service_rating(N, opts=None): def Service_rating(N, opts=None):
try:
opts = opts or {} opts = opts or {}
Order_data = [] Order_data = []
req_et = [] req_et = []
@ -458,7 +465,7 @@ def Service_rating(N, opts=None):
'//*[@id="main"]/div[2]/div[2]/table/tbody/tr[@class="tr-bd"]') '//*[@id="main"]/div[2]/div[2]/table/tbody/tr[@class="tr-bd"]')
opts['logger'].debug('Count of fetched order data: %d', len(elems)) opts['logger'].debug('Count of fetched order data: %d', len(elems))
Order_data.extend(elems) Order_data.extend(elems)
#if len(Order_data) != N['服务评价']: # if len(Order_data) != N['服务评价']:
# opts['logger'].debug( # opts['logger'].debug(
# 'Count of fetched order data doesn\'t equal N["服务评价"]') # 'Count of fetched order data doesn\'t equal N["服务评价"]')
# opts['logger'].debug('Clear the list Order_data') # opts['logger'].debug('Clear the list Order_data')
@ -509,7 +516,8 @@ def Service_rating(N, opts=None):
time.sleep(SERVICE_RATING_SLEEP_SEC) time.sleep(SERVICE_RATING_SLEEP_SEC)
N['服务评价'] -= 1 N['服务评价'] -= 1
return N return N
except Exception as e:
print (e)
def No(opts=None): def No(opts=None):
opts = opts or {} opts = opts or {}
@ -523,7 +531,7 @@ def No(opts=None):
def main(opts=None): def main(opts=None):
opts = opts or {} opts = opts or {}
opts['logger'].info("开始京东自动评价!") #opts['logger'].info("开始京东自动评价!")
N = No(opts) N = No(opts)
opts['logger'].debug('N value after executing No(): %s', N) opts['logger'].debug('N value after executing No(): %s', N)
if not N: if not N:
@ -547,7 +555,7 @@ def main(opts=None):
opts['logger'].debug('N value after executing Service_rating(): %s', N) opts['logger'].debug('N value after executing Service_rating(): %s', N)
N = No(opts) N = No(opts)
opts['logger'].debug('N value after executing No(): %s', N) opts['logger'].debug('N value after executing No(): %s', N)
opts['logger'].info("本次运行完成!") opts['logger'].info("该账号运行完成!")
if __name__ == '__main__': if __name__ == '__main__':
@ -643,16 +651,23 @@ if __name__ == '__main__':
#print() #print()
#logger.debug('Closed the configuration file') #logger.debug('Closed the configuration file')
#logger.debug('Configurations in Python-dict format: %s', cfg) #logger.debug('Configurations in Python-dict format: %s', cfg)
cks = []
if "PC_COOKIE" in os.environ: if "PC_COOKIE" in os.environ:
if len(os.environ["PC_COOKIE"]) > 200: if len(os.environ["PC_COOKIE"]) > 200:
ck = os.environ["PC_COOKIE"] if '&' in os.environ["PC_COOKIE"]:
logger.info ("已获取环境变量 CK") cks = os.environ["PC_COOKIE"].split('&')
else:
cks.append(os.environ["PC_COOKIE"])
else: else:
logger.info ("CK错误请确认是否电脑版CK") logger.info ("CK错误请确认是否电脑版CK")
sys.exit(1) sys.exit(1)
logger.info ("已获取环境变量 CK")
else: else:
logger.info("没有设置变量PC_COOKIE请添加电脑端CK到环境变量") logger.info("没有设置变量PC_COOKIE请添加电脑端CK到环境变量")
sys.exit(1) sys.exit(1)
try:
i = 1
for ck in cks:
headers = { headers = {
'cookie': ck.encode("utf-8"), 'cookie': ck.encode("utf-8"),
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',
@ -673,10 +688,10 @@ if __name__ == '__main__':
'Accept-Language': 'zh-CN,zh;q=0.9', 'Accept-Language': 'zh-CN,zh;q=0.9',
} }
logger.debug('Builtin HTTP request header: %s', headers) logger.debug('Builtin HTTP request header: %s', headers)
logger.debug('Starting main processes') logger.debug('Starting main processes')
try: print ('\n开始第 '+ str(i) +'个账号评价。。。\n')
main(opts) main(opts)
i += 1
# NOTE: It needs 3,000 times to raise this exception. Do you really want to # NOTE: It needs 3,000 times to raise this exception. Do you really want to
# do like this? # do like this?
except RecursionError: except RecursionError: