zoukankan      html  css  js  c++  java
  • python 2.7中文字符串的匹配(参考)

    #!/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()
    

      

    刚开始使用中文匹配的,后来改变了策略。

  • 相关阅读:
    python邮件之附件
    python3.5之smtp
    一台Linux上搭建两个tomcat
    mysql 初探(一)
    python监视mysql最大连接数
    P3658 [USACO17FEB]Why Did the Cow Cross the Road III P cdq分治
    P4793 [AHOI2008]矩形藏宝地 cdq分治 线段树
    P2487 [SDOI2011]拦截导弹 线段树 cdq分治
    P3157 [CQOI2011]动态逆序对 cdq分治
    P4169 [Violet]天使玩偶/SJY摆棋子 cdq分治
  • 原文地址:https://www.cnblogs.com/bill2014/p/8301162.html
Copyright © 2011-2022 走看看