python 通过手机号识别出对应的微信性别

def getGender(self,tel):
   self.d(resourceId="com.tencent.mm:id/kh").clear_text()
   self.d(resourceId="com.tencent.mm:id/kh").set_text(tel)        
   self.d(resourceId="com.tencent.mm:id/mf").click()                
   time.sleep(1)
   self.d.watcher("AccNotExist").when(text="该用户不存在").click(resourceId="com.tencent.mm:id/kd")
   self.d.watcher("AccException").when(text="被搜帐号状态异常,无法显示").click(resourceId="com.tencent.mm:id/kd"
   self.d.watchers.run()
   AccNotExist  = self.d.watcher("AccNotExist").triggered
   AccException = self.d.watcher("AccException").triggered
   OperationFrequently = self.d.watcher("OperationFrequently").triggered
   if AccNotExist:
      self.d.watchers.reset()
      return "用户不存在"
   elif AccException:
      self.d.watchers.reset()
      return "被搜帐号状态异常,无法显示"
   elif OperationFrequently:
      self.d.watchers.reset()
   if self.d(resourceId="com.tencent.mm:id/b3y").exists:
      gender = self.d(resourceId="com.tencent.mm:id/b3y").info['contentDescription']
      self.d(resourceId="com.tencent.mm:id/kb").click()  # back
      return gender
   else:
      self.d(resourceId="com.tencent.mm:id/kb").click()  # back
      return "用户未设置性别"

def write_excel_xls(self,pathfile, value):
   index = len(value)  
   workbook = xlwt.Workbook()  # 新建一个工作簿
   sheet1 = workbook.add_sheet("boy")  # 在工作簿中新建一个表格
   sheet2 = workbook.add_sheet("girl")
   sheet3 = workbook.add_sheet("NotSet")
   sheet4 = workbook.add_sheet("NotExist")
   sheet5 = workbook.add_sheet("AccountE")
   def writesheet(self,sheet):
      for i in range(0, index):
         for j in range(0, len(value[i])):
            sheet.write(i, j, value[i][j])  # 像表格中写入数据(对应的行和列)
      workbook.save(pathfile)  # 保存工作簿
   writesheet(self,sheet1)
   writesheet(self,sheet2)
   writesheet(self,sheet3)
   writesheet(self,sheet4)
   writesheet(self,sheet5)
def write_excel_xls_append(self,pathfile, sheet_name, value):
   index = len(value)  # 获取需要写入数据的行数
   workbook = xlrd.open_workbook(pathfile)  # 打开工作簿
   # sheets = workbook.sheet_names()  # 获取工作簿中的所有表格
   worksheet = workbook.sheet_by_name(sheet_name)  # 获取工作簿中所有表格中的的第一个表格
   rows_old = worksheet.nrows  # 获取表格中已存在的数据的行数
   new_workbook = copy(workbook)  # 将xlrd对象拷贝转化为xlwt对象
   new_worksheet = new_workbook.get_sheet(sheet_name)  # 获取转化后工作簿中的第一个表格
   for i in range(0, index):
      for j in range(0, len(value[i])):
         new_worksheet.write(i + rows_old, j, value[i][j])  # 追加写入数据,注意是从i+rows_old行开始写入
   new_workbook.save(pathfile)  # 保存工作簿
   # print("%s【追加】写入数据成功!" % pathfile)

def read_excel_xls(self,pathfile, sheet_name):
   workbook = xlrd.open_workbook(pathfile)  # 打开工作簿
   sheets = workbook.sheet_names()  # 获取工作簿中的所有表格
   worksheet = workbook.sheet_by_name(sheet_name)  # 获取工作簿中所有表格中的的第一个表格
   for i in range(0, worksheet.nrows):
      for j in range(0, worksheet.ncols):
         print(worksheet.cell_value(i, j), "\t", end="")  # 逐行逐列读取数据

你可能感兴趣的:(python)