同步bug状态

import openpyxl
import re
import requests

def readbugid(path):
#读取excel的bugid
excel=openpyxl.load_workbook(path)
sheet=excel['Bug状态']
max_row=sheet.max_row
bugid=[]
for a in range(2,max_row+1):
value=sheet.cell(row=a,column=2).value
bugid.append(value)
return bugid
# print(readbugid('D:zhaopython-src-210222 - 副本.xlsx'))

def readstatus(text):
#接收bugid页面的的text,返回此bug的status
str=text
guize='.*</span>(.*),.*?</span></span><span'
status=re.match(guize,str).group(1)
return status
# print(readstatus(a))

def request(bugid):
#接受bugid,返回这个bugid的状态
url='http://xxxxxx/{}'.format(bugid)
headers={ "Cookie":"xxxxxxxxxxxxxx"}
ret=requests.get(url=url,headers=headers)
text=ret.text
stutas=readstatus(text)
return stutas


def write(path,x,status):
homepath=path
workbook=openpyxl.load_workbook(homepath)
sheet=workbook['Bug状态']
a=sheet.cell(row=x,column=2).value
if a==None:
pass
else:
if a==status:
pass
else:
sheet.cell(row=x,column=4).value=sheet.cell(row=x,column=4).value+'-'+status
workbook.save(homepath)
# write(x=7,status='t12345')

def run(path):
path=path
bugid=readbugid(path)
row=2
for bug in bugid:
row+=1
url_status=request(bug)
print(url_status)
write(path=path,x=row,status=url_status)

if __name__ == '__main__':
run(r'D:赵xx自动化11111-所有的日报6125_Di3平台自动化测试报告-210309.xlsx')

原文地址:https://www.cnblogs.com/zhaobobo10/p/15064560.html