import re,csv
import requests
projects_url='http://svnpub.xurikeji.com:8081/usvn1/admin/project'
project_url=projects_url.split("admin")[0]+"project/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
'Cookie':'_ga=GA1.1.1852336263.1700719769; _ga_0C4M1PWYZ7=GS1.1.1700719769.1.0.1700719810.0.0.0; _ga_T11SF3WXX2=GS1.1.1700719790.1.0.1700719810.40.0.0; _ga_K2SPJK2C73=GS1.1.1700719790.1.0.1700719810.40.0.0; PHPSESSID=ipqe60ge4pjnfbqdahe0nj2oh2'
}
file = open('C:\\Users\\xurikeji\\Desktop\\my_list.csv', 'a', newline='')
def project():
response = requests.get(projects_url, headers=headers)
html = response.text
project_name_desc_re = re.compile(r'(?P.*?) | .*?(?P.*?) | ',re.S)
project_names_descs = project_name_desc_re.finditer(html)
for project_name_desc in project_names_descs:
info(project_name_desc.group('name'),project_name_desc.group('describe'))
file.close()
def info(project_name,project_describe):
url=project_url+project_name
response = requests.get(url, headers=headers)
if response.status_code == 500:
print("GET请求返回状态码为500,跳出函数")
return
html = response.text
project_admins_re = re.compile(r'您确定要取消用户 (?P.*?) 对于项目 .*? 的管理权\?',re.S)
project_users_re = re.compile(r'您确定要将用户组 (?P.*?) 从项目 .*? 中删除\?', re.S)
recently_commit_info_re = re.compile(r'(?P.*?) | .*?(?P.*?) | .*?(?P.*?) | .*?', re.S)
project_admins = project_admins_re.finditer(html)
project_users = project_users_re.finditer(html)
recently_commit_info = recently_commit_info_re.findall(html)
admins=[]
users=[]
for project_admin in project_admins:
admins.append(project_admin.group('admin'))
for project_user in project_users:
users.append(project_user.group('user'))
admins = ','.join(admins)
users = ','.join(users)
if len(recently_commit_info) > 0 and len(recently_commit_info[0]) > 0:
recently_commit_infos = ','.join(recently_commit_info[0])
else:
recently_commit_infos = '无'
print("项目名:",project_name)
print("项目描述:",project_describe)
print("项目管理员:",admins)
print("项目用户组:",users)
print("信息:",recently_commit_infos)
print("======================================================")
writer = csv.writer(file)
writer.writerow([project_name,project_describe,admins,users,recently_commit_infos])
admins=[]
users=[]
if __name__ == '__main__':
project()