首页 > 代码库 > Python监控网站接口值
Python监控网站接口值
Python监控网站接口值:
#!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = ‘liudong‘ import urllib,sys,urllib2,json,smtplib from email.mime.text import MIMEText mailto_list=[‘邮箱‘] mail_host="smtp.philisense.com" mail_user="邮箱" mail_pass="邮箱密码" mail_postfix="philisense.com" def send_mail(to_list,sub,content): me="hello"+"<"+mail_user+"@"+mail_postfix+">" msg = MIMEText(content,_subtype=‘plain‘) msg[‘Subject‘] = sub msg[‘From‘] = me msg[‘To‘] = ";".join(to_list) try: server = smtplib.SMTP(mail_host,25) server.set_debuglevel(1) server.login(mail_user,mail_pass) server.sendmail(me, to_list, msg.as_string()) server.close() except : return False #把 接口:参数,以(key :value)写成字典的方式 api_host ={"http://back.oursdata.com/jppt/jp-index-data/hours-data":{"appid":"1,2,3,4", "indexType":"node_activeness_count", "dateType":"month", "startDate":"2016/6/25", "endDate":"2016/12/21"}, "http://back.oursdata.com/jppt/jp-index-data/avg-day":{"appid":"1, 2, 3, 4, 5", "indexType":"active_avg", "dateType":"week", "_csrf":"Q2lwdWd0ekQaXkgANEEDMy89RVgORzsLJAs4MgVMKBYiOy8aBgZMCA=="} } #给函数定义两个参数 def interfaceTest(api_url,parameter): params = urllib.urlencode(parameter) headers = {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"} req = urllib2.Request(url=api_url, data=http://www.mamicode.com/params, headers=headers) response = urllib2.urlopen(req) a = json.loads(response.read()) if a["err"] == "ok": if len(a["data"]) == 0: send_mail(mailto_list,‘data‘,k + ‘\n‘ ‘The data is None!!!‘) else: send_mail(mailto_list, ‘err‘,‘"err" not equal to "ok"‘) if __name__ == "__main__": for (k,v) in api_host.items(): interfaceTest(k,v) #给函数传参
Python监控网站接口值
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。