#!/bin/env python #-*- coding:utf-8 -*- import urllib import os,sys,json import ssl context = ssl._create_unverified_context() def GetWorkOrder(ip): try: #ip = sys.argv[1] len(ip) != 1 except: print "error paras!!" else: #bxurl='**' + ip + '&type=fwqbx' zjurl='***' + ip + '&type=fwqzj' #bx = urllib.urlopen(bxurl, context=context) zj = urllib.urlopen(zjurl, context=context) #bxr = bx.read(bx) zjr = zj.read(zj) #lbxr = json.loads(bxr) lzjr = json.loads(zjr) #print json.dumps(lbxr,ensure_ascii=False,sort_keys=True, indent=2) #zjlist=json.dumps(lzjr,ensure_ascii=False,sort_keys=True, indent=2) #print zjlist try: #t1= lzjr[0]['data']['detail'][0]['sn'] t2= lzjr[0]['data']['detail'][0]['statusname'] #print t2 return t2 #return t2.decode('utf-8').encode('gbk') except: pass #GetWorkOrder() def sn_GetWorkOrder(ip): try: #ip = sys.argv[1] len(ip) != 1 except: print "error paras!!" else: #bxurl='https://portal.qiyi.domain/newportal/?appkey=getprolist&ip=' + ip + '&type=fwqbx' zjurl='https://portal.qiyi.domain/newportal/?appkey=getprolist&ip=' + ip + '&type=fwqzj' #bx = urllib.urlopen(bxurl, context=context) zj = urllib.urlopen(zjurl, context=context) #bxr = bx.read(bx) zjr = zj.read(zj) #lbxr = json.loads(bxr) lzjr = json.loads(zjr) #print json.dumps(lbxr,ensure_ascii=False,sort_keys=True, indent=2) #zjlist=json.dumps(lzjr,ensure_ascii=False,sort_keys=True, indent=2) #print zjlist try: t1= lzjr[0]['data']['detail'][0]['sn'] #t2= lzjr[0]['data']['detail'][0]['statusname'] return t1 except: pass if __name__ == '__main__': #tt = '结束'.decode('utf-8').encode('gbk') #print tt input = open('data','r') while True: tmp_ip = input.readline() #print tmp_ip status = GetWorkOrder(tmp_ip) #status = status.decode('utf-8').encode('gbk') try: print len(status) except: pass try: if len(status) != 2: tmp_sn = sn_GetWorkOrder(tmp_ip) #print tmp_sn cmd1 = "echo "+'"'+str(tmp_ip)+str(tmp_sn)+'"'+ " >> /tmp/b.txt" #print cmd1 os.system(cmd1) except: pass input.close()
刚开始使用中文匹配的,后来改变了策略。