def postV1CommentLike(id, titleNo, episodeNo, flag="like"): path = "/v1/comment/%s/like" % id titleNo = str(titleNo) episodeNo = str(episodeNo) payload = { "flag": flag, "titleNo": titleNo, "episodeNo": episodeNo, } payload.update(Config("baseparams")) try: resp = requests.post(Config("httphost") + path, params=getExpiresMd5(path), data=payload, headers=Config("headers"), cookies=Config("cookies")) result = resp.json() logger.info(resp.url) # logger.info(resp.request.headers) logger.info(resp.request.body) logger.info(result) return result except Exception: logger.exception("postV1CommentLike发生异常")
def login(username, passwd, loginType="EMAIL"): ##PHONE_NUMBER path = "/app/member/id/login" ne = appRsakeyGet() if ne: try: encpw = rsaEnc(ne[2], ne[1], ne[3], mobile=username, passwd=passwd) encnm = ne[0] plus = { "loginType": loginType, "encnm": encnm, "encpw": encpw, "v": 1 } plus.update(Config("baseparams")) resp = requests.post(Config("httphost") + path, headers=Config("headers"), data=plus, params=getExpiresMd5(path)) resp_json = resp.json() logger.info(resp.url) neo_ses = resp_json["message"]["result"]["ses"] neo_id = resp_json["message"]["result"]["id_no"] updateConfig("neo_ses", neo_ses) updateConfig("neo_id", neo_id) return neo_ses, resp_json["message"]["result"]["idNo"] except Exception: logger.exception("login出现异常") logger.error(resp.url) logger.error(resp.text) # logger.error(resp.headers) return False else: return False
def v1CommentReply(parentId, titleNo, episodeNo, text=""): path = "/v1/comment_reply" titleNo = str(titleNo) episodeNo = str(episodeNo) text = str(text) objectId = "w_" + titleNo + "_" + episodeNo # print(objectId) time_now = datetime.datetime.now() otherStyleTime = time_now.strftime("%Y-%m-%d %H:%M:%S") if text: contents = text + "_" + str(otherStyleTime) else: contents = "自动生成回复_" + str(otherStyleTime) payload = { "contents": contents, "parentId": parentId, "objectId": objectId } payload.update(Config("baseparams")) try: resp = requests.post(Config("httphost") + path, params=getExpiresMd5(path), data=payload, headers=Config("headers"), cookies=Config("cookies")) result = resp.json() # logger.info(resp.url) # logger.info(resp.request.body) # logger.info(result) return result except Exception: logger.exception("v1CommentReply发生异常")
def v2Comment(titleNo, episodeNo, imageNo="", pageNo="", sortBy="", limit=""): path = "/v2/comment" payload = { "titleNo": titleNo, "episodeNo": episodeNo, "imageNo": imageNo, "pageNo": pageNo, "sortBy": sortBy, "limit": limit } payload.update(Config("baseparams")) payload.update(getExpiresMd5(path)) try: resp = requests.get(Config("httphost") + path, params=payload, headers=Config("headers"), cookies=Config("cookies")) logger.info(resp.url) if resp.ok: result = resp.json() if result["code"] == 200: pass # logger.info(result.keys()) # logger.info(result["data"].keys()) # logger.info(result["data"]["commentList"][0].keys()) # logger.info(result["data"]["commentList"][0]["commentReplyList"][0].keys()) # logger.info(result["data"]["bestList"][0].keys()) # logger.info(result["data"]["bestList"][0]["commentReplyList"][0].keys()) return result except Exception: logger.exception("v2Comment发生异常")
def postV1CommentReplyComplaint(id): path = "/v1/comment_reply/%s/complaint" % id payload = Config("baseparams") try: resp = requests.post(Config("httphost") + path, params=getExpiresMd5(path), data=payload, headers=Config("headers"), cookies=Config("cookies")) return resp.json() except Exception: logger.exception("postV1CommentReplyComplaint发生异常")
def v1Comment(titleNo, episodeNo, categoryImage="", categoryId="", imageNo="", text="", userType=""): path = "/v1/comment" titleNo = str(titleNo) episodeNo = str(episodeNo) text = str(text) objectId = "w_" + titleNo + "_" + episodeNo # print(objectId) time_now = datetime.datetime.now() otherStyleTime = time_now.strftime("%Y-%m-%d %H:%M:%S") if not text: contents = "自动生成回复_" + str(otherStyleTime) if userType: payload = { "categoryId": categoryId, "categoryImage": categoryImage, "contents": text, "episodeNo": episodeNo, "imageNo": imageNo, "objectId": objectId, "titleNo": titleNo, "userType": userType } else: payload = { "categoryId": categoryId, "categoryImage": categoryImage, "contents": text, "episodeNo": episodeNo, "imageNo": imageNo, "objectId": objectId, "titleNo": titleNo, } payload.update(Config("baseparams")) try: resp = requests.post(Config("httphost") + path, params=getExpiresMd5(path), data=payload, headers=Config("headers"), cookies=Config("cookies")) result = resp.json() # logger.info(resp.url) # logger.info(resp.request.body) # logger.info(result) return result except Exception: logger.exception("v1Comment出现异常")
def setConfig(section, option, value, ini="session.ini"): try: conf = configparser.ConfigParser(dict_type=OrderedDict) conf.read(ini) if conf.has_section(section): pass else: conf.add_section(section) conf.set(section, option, value) except Exception: logger.exception("setConfig错误") finally: conf.write(open(ini, "r+")) time.sleep(5)
def v1CommentOwnAll(flag="", id="", pageNo=1): path = "/v1/comment/ownall" payload = {"limit": 20, "pageNo": pageNo, "flag": flag, "_id": id} payload.update(Config("baseparams")) payload.update(getExpiresMd5(path)) resp = requests.get(Config("httphost") + path, params=payload, headers=Config("headers"), cookies=Config("cookies")) logger.info(resp.url) if resp.ok: result = resp.json() return result else: logger.exception("v1CommentOwnAll发生异常")
def deleteCommentReply(id): path = "/v1/comment_reply/%s" % id payload = Config("baseparams") try: resp = requests.delete(Config("httphost") + path, params=getExpiresMd5(path), data=payload, headers=Config("headers"), cookies=Config("cookies")) logger.info(resp.url) if resp.ok: result = resp.json() logger.info(result) assert result["code"] == 200 assert result["message"] == "请求成功!" except Exception: logger.exception("deleteCommentReply发生异常")
def v1CommentReplyGet(commentId, pageNo, limit=10): path = "/v1/comment_reply" payload = {"commentId": commentId, "pageNo": pageNo, "limit": limit} payload.update(Config("baseparams")) payload.update(getExpiresMd5(path)) try: resp = requests.get(Config("httphost") + path, params=payload, headers=Config("headers"), cookies=Config("cookies")) result = resp.json() if result["code"] == 200: pass # logger.info(result['data']["commentReplyList"][0].keys()) return result except Exception: logger.exception("v1CommentReplyGet发生异常")
def v1CommentDetail(titleNo, episodeNo, commentId, replyCommentId="", commentLimit=20, commentReplyLimit=10, imageNo=""): path = "/v1/comment/detail" payload = { "titleNo": titleNo, "episodeNo": episodeNo, "imageNo": imageNo, "commentId": commentId, "replyCommentId": replyCommentId, "commentLimit": commentLimit, "commentReplyLimit": commentReplyLimit, } payload.update(Config("baseparams")) payload.update(getExpiresMd5(path)) try: resp = requests.get(Config("httphost") + path, params=payload, headers=Config("headers"), cookies=Config("cookies")) logger.info(resp.url) if resp.ok: result = resp.json() if result["code"] == 200: pass # logger.info(result.keys()) # logger.info(result["data"].keys()) # logger.info(result["data"]["comment"].keys()) # logger.info(result["data"]["comment"]["commentList"][0].keys()) # logger.info(result["data"]["comment"]["pageModel"].keys()) # logger.info(result["data"]["comment"]["bestList"][0].keys()) # logger.info(result["data"]["replyComment"].keys()) # logger.info(result["data"]["replyComment"]["commentReplyList"][0].keys()) # logger.info(result["data"]["replyComment"]["pageModel"].keys()) return result except Exception: logger.exception("v1CommentDetail发生异常")
def sendMail(now_time, report_name, source="results", output="results_%s.zip"): ''' 'gjhpbxfvvuxhdhid' 'dxnuqtwtnqngdjbi' ''' source = os.path.join(os.path.dirname(__file__), source) output = output % now_time output = os.path.join(os.path.dirname(__file__), "resultszip", output) make_zip(source, output) # sender = '*****@*****.**' # smtpserver = 'smtp.qq.com' # password = '******' sender = '*****@*****.**' smtpserver = 'smtp.163.com' password = "******" # username = '******' toList = ['*****@*****.**', '*****@*****.**'] receiver = ", ".join(toList) toTo = "木木QQ<%s>, Neal<%s>" % tuple(toList) mail_title = report_name # 创建一个带附件的实例 message = MIMEMultipart() message['From'] = "木木<%s>" % sender message['To'] = toTo message['Subject'] = Header(mail_title, 'utf-8') # 邮件正文内容 mail_html = handleHtml(report_name) message.attach(MIMEText('测试结果见报告', 'plain', 'utf-8')) message.attach(MIMEText(mail_html, 'html', 'utf-8')) try: smtp = smtplib.SMTP() # smtp = smtplib.SMTP_SSL(smtpserver) # 注意:如果遇到发送失败的情况(提示远程主机拒接连接),这里要使用SMTP_SSL方法 smtp.set_debuglevel(1) smtp.connect(smtpserver) smtp.login(sender, password) with open(output, 'rb') as f: # 这里附件的MIME和文件名 mime = MIMEBase('zip', 'zip', filename=report_name) # 加上必要的头信息 mime.add_header('Content-Disposition', 'attachment', filename=('utf-8', '', "%s.zip" % report_name)) mime.add_header('Content-ID', '<0>') mime.add_header('X-Attachment-Id', '0') # 把附件的内容读进来 mime.set_payload(f.read()) # 用Base64编码 encoders.encode_base64(mime) message.attach(mime) # smtp.sendmail(sender, receiver.split(","), message.as_string()) smtp.sendmail(sender, toList, message.as_string()) except Exception: logger.exception("邮件发送失败!") else: logger.info("邮件发送成功!") finally: smtp.quit()