def pay_cj(self, lotteryid): html, data_info = self.pc_touzhu(lotteryid) soup = BeautifulSoup(html, 'html5lib') sign = [x.get('value') for x in soup.find_all('input', id='ext_sign')][0] url = readconfig('pay_cj') datas = { 'userid': data_info.get('userid'), 'pid': data_info.get('pid'), 'sid': data_info.get('sid'), 'inputrmb': 0, 'inputrmbtp': data_info.get('amount'), 'prebuyid': data_info.get('prebuyid'), 'isdjq': 0, 'djqid': 0, 'isredbag': 0, 'redbagid': 0, 'iswlt': 0, 'istpoint': 0, 'sendtime': 0, 'mobile': readconfig('mobile'), 'orderid': data_info.get('orderid'), 'fangan': 0, 'danbao': 0, 'selfdb': 0, 'fanyong': 5, 'limit_flag': 'true', 'ext_sign': sign, 'inputrmbcf': data_info.get('amount'), 'support_fangan': 1 } info = self.session.post(url=url, data=datas, cookies=self.cookie).json() return info
def dojobww(): # 邮件正文模板 maildata = '''系统运行状态: [系统运行结果] -------------------------- 1.外网房源标注同步: [状态1] OGG最后处理时间: [trial时间] 2.外网网闸:[网闸状态2] 最后同步时间:[网闸同步时间2] -------------------------- 最后检查时间: [检查时间]''' tools.writeLog('----------外网监控任务:开始!----------') #1 检查外网房源标注OGG运行状态 delaydays = tools.readconfig('dealOGGlog', 'delaydays_r_i_ba') oggresult = dealOGGlogfile.getcheckOGGr_i_ba(int(delaydays)) #2 检查外网网闸工作状态 gappathww = tools.readconfig('gap', 'shuiwu_nankang_gap_path') gapdaysww = tools.readconfig('gap', 'shuiwu_nankang_gap_time') gapresultww = dealgapfile.checkgap(gappathww, int(gapdaysww)) # 根据监控结果,编写邮件正文内容 #1 外网OGG状态 if oggresult[0] == 0: maildata = maildata.replace('[状态1]', '正常') maildata = maildata.replace('[trial时间]', oggresult[1]) else: maildata = maildata.replace('[状态1]', '异常') maildata = maildata.replace('[trial时间]', '异常') #2 外网网闸 if gapresultww[0] == 0: maildata = maildata.replace('[网闸状态2]', '正常') maildata = maildata.replace('[网闸同步时间2]', gapresultww[1]) elif gapresultww[0] == 1: maildata = maildata.replace('[网闸状态2]', '异常') maildata = maildata.replace('[网闸同步时间2]', gapresultww[1]) else: maildata = maildata.replace('[网闸状态2]', '异常') maildata = maildata.replace('[网闸同步时间2]', '未找到数据') # 系统整体运行状态 if oggresult[0] == 0 and gapresultww[0] == 0: maildata = maildata.replace('[系统运行结果]', '全部正常!') else: maildata = maildata.replace('[系统运行结果]', '发生异常!') maildata = maildata.replace('[检查时间]', tools.nowtime()) tools.writeLog('外网监控结果:\n' + maildata) tools.writeLog('----------外网监控任务:结束!----------') return maildata
def getcheckOGGr_i_ba(delaydays): ''' 监控R_I_BA进程 返回值:result:0-正常;1-异常 ; ''' cmdstr = tools.readconfig('dealOGGlog', 'cmdStr') downloadfile(cmdstr) trialsplit = tools.readconfig('dealOGGlog', 'trailsplit') trailfilepath = tools.readconfig('dealOGGlog', 'trailfilepath') trailfile = splitOGGlog(trailfilepath, trialsplit) result = checkOGGLogfile(trailfile[1], delaydays) return result, trailfile[1]
def sendmail(maildata): sender = tools.readconfig('mail', 'sender') receiver = tools.readconfig('mail', 'receiver') subject = tools.readconfig('mail', 'subject') smtpserver = tools.readconfig('mail', 'smtpserver') username = tools.readconfig('mail', 'username') password = tools.readconfig('mail', 'password') attachfile = tools.readconfig('mail', 'attachfile') msgRoot = MIMEMultipart('related') msgRoot['Subject'] = subject date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) msgText = MIMEText(date + maildata, _subtype='plain', _charset='gb2312') msgRoot.attach(msgText) # 构造附件 if attachfile != '': att = MIMEText(open(attachfile, 'rb').read(), 'base64', 'utf-8') att["Content-Type"] = 'application/octet-stream' att["Content-Disposition"] = 'attachment; filename="parameter.ini"' msgRoot.attach(att) smtp = smtplib.SMTP() smtp.connect(smtpserver) # smtp.login(username, password) smtp.sendmail(sender, receiver, msgRoot.as_string()) smtp.quit() tools.writeLog('邮件已发送给:' + receiver)
def __init__(self): self.mem = Memcache() self.base_url = readconfig('base_url') self.cookie = eval(self.mem.getmem('caipiao_pc_login_cookie')) cookie_jar = requests.utils.cookiejar_from_dict(self.cookie, cookiejar=None, overwrite=True) self.session = requests.Session() self.session.cookies = cookie_jar
def downloadfile(cmdstr): ''' 传入下载命令,通过putty工具进行下载 ''' tools.writeLog('传输FTP日志:开始') # 更改本地目录到psftp工具的路径 localpath = tools.readconfig('dealOGGlog', 'localPath') os.chdir(localpath) # 下载 os.system(cmdstr) tools.writeLog('传输FTP日志:结束')
def pc_touzhu(self, lotteryid): import urllib #获取投注form表单,pc_bet_data传递的参数详情见data文件中的bet_info if lotteryid > 10000: forms_data = pc_bet_data(lotteryid) print lotteryid print forms_data bet_url = readconfig('num_bet_url') print bet_url else: forms_data = eval( self.mem.getmem("bet_{lotteryid}".format(**locals())).replace( ' ', '')) if lotteryid == 2521: forms_data['lotterytype'] = 'exy' if lotteryid in num_for_lotteryid('jclq'): bet_url = readconfig('jclq_bet_url') elif lotteryid in num_for_lotteryid('jczq'): bet_url = readconfig('jczq_bet_url') #发送投注请求 print bet_url print forms_data s = self.session.post(url=bet_url, data=forms_data).content if eval(s).get('url'): # 获取返回值中的url参数 url = eval(s).get('url') else: logger('投注失败', "投注结果:{}".format(s)) return # 拼接url url = self.base_url + urllib.unquote(url)[1:] # 获取url中的参数信息,以字典形式返回 data_info = url2Dict(url) #记录投注结果 logger( lotteryid, "{}投注成功,orderid:{}".format(data_info.get('lotteryname'), data_info.get('orderid'))) # 请求上一个请求返回的url,跳转支付页面 html = self.session.get(url).content #返回支付页面html及sid,userid等data信息 return html, data_info
str(filelastmtime)) return filelastmname, filelastmtime, fileflag def checkgap(gappath, gapsyndays): ''' 根据网闸文件最后修改时间检查网闸工作情况 返回值:result: 0-正常,1-有过同步,但异常 , 2-网闸目录不存在,或者目录下没有文件 ; 最后修改时间 string ''' result = getfolderlastmtime(gappath) # 有结果的话,进行时间判断 if result[2] != 1: legalday = datetime.datetime.now() - datetime.timedelta( days=gapsyndays) if result[1] <= legalday: tools.writeLog('网闸[' + gappath + ']检查完毕,结果:异常') return 1, result[1].strftime('%Y-%m-%d %H:%M:%S') # 异常,需处理 else: tools.writeLog('网闸[' + gappath + ']检查完毕,结果:正常') return 0, result[1].strftime('%Y-%m-%d %H:%M:%S') # 没问题 else: tools.writeLog('网闸文件夹下没文件,异常!') return 2, result[1] if __name__ == '__main__': gap_path = tools.readconfig('gap', 'shuiwu_nankang_gap_path') gapdays = tools.readconfig('gap', 'shuiwu_nankang_gap_time') result = checkgap(gap_path, int(gapdays)) print(result)
def get_user_info(self): #获取用户信息接口 url = readconfig('get_userinfo') s = self.session.get(url, cookies=self.cookie) info = s.json() return info
import threading import tools import jobww RESPONSE_TEXT_TEMPLATE = ''' <xml> <ToUserName><![CDATA[{TO_USER}]]></ToUserName> <FromUserName><![CDATA[{FROM_USER}]]></FromUserName> <CreateTime>{TIME_STEMP}</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[{RESPONSE_CONTENT}]]></Content> </xml> ''' # MYURL_STG = 'http://zengjc.eicp.net' # MYURL_PRD = 'http://218.242.60.232' TOKEN = tools.readconfig('weixin', 'TOKEN') SPECIAL_CMD = tools.readconfig('weixin', 'SPECIAL_CMD') SPECIAL_USERID = tools.readconfig('weixin', 'SPECIAL_USERID') MONITOR_CMD = tools.readconfig('weixin', 'MONITOR_CMD') # 命令最低间隔时间(秒) INTERVALTIME = int(tools.readconfig('weixin', 'INTERVALTIME')) # 普通用户命令最低间隔时间(秒) MONITOR_INTERVALTIME = int(tools.readconfig('weixin', 'MONITOR_INTERVALTIME')) # 最后一次执行命令的时间,在每次执行成功命令后更新 LASTDONETIME = datetime.datetime.now() MONITOR_RESULT = None class Handler(BaseHTTPRequestHandler): def do_GET(self): print (threading.currentThread().getName())
tools.writeLog('网闸[' + folderpath + ']下最后修改的文件名称:' + os.path.basename(filelastmname) + ' ;最后修改时间为:' + str(filelastmtime)) return filelastmname, filelastmtime, fileflag def checkgap(gappath, gapsyndays): ''' 根据网闸文件最后修改时间检查网闸工作情况 返回值:result: 0-正常,1-有过同步,但异常 , 2-网闸目录不存在,或者目录下没有文件 ; 最后修改时间 string ''' result = getfolderlastmtime(gappath) # 有结果的话,进行时间判断 if result[2] != 1 : legalday = datetime.datetime.now() - datetime.timedelta(days=gapsyndays) if result[1] <= legalday: tools.writeLog('网闸[' + gappath + ']检查完毕,结果:异常') return 1,result[1].strftime('%Y-%m-%d %H:%M:%S') # 异常,需处理 else: tools.writeLog('网闸[' + gappath + ']检查完毕,结果:正常') return 0,result[1].strftime('%Y-%m-%d %H:%M:%S') # 没问题 else: tools.writeLog('网闸文件夹下没文件,异常!') return 2,result[1] if __name__ == '__main__': gap_path = tools.readconfig('gap', 'shuiwu_nankang_gap_path') gapdays = tools.readconfig('gap', 'shuiwu_nankang_gap_time') result = checkgap(gap_path, int(gapdays)) print (result)