腾讯coding解析excel批量创建任务python脚本

import requests
import json
import openpyxl
# 设置请求头
from pyasn1.compat.octets import null

headers = {
    'Authority': 'xxx1.coding.net',
    'Method': 'POST',
    'Path': '/api/project/10655274/issues/missions',
    'Scheme': 'https',
    'Accept': 'application/json',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Coding-Collaboration-Origin-Template-Id': '0',
    'Coding-Collaboration-Template-Id': '3247453',
    'Content-Length': '406',
    'Content-Type': 'application/json;charset=UTF-8',
    'Cookie': 'exp=89cd78c2; code=artifact-reforge%3Dfalse%2Casync-blocked%3Dtrue%2Cauth-by-wechat%3Dtrue%2Cci-qci%3Dfalse%2Cci-team-step%3Dfalse%2Cci-team-templates%3Dfalse%2Ccoding-flow%3Dfalse%2Ccoding-ocd-java%3Dfalse%2Ccoding-ocd-pages%3Dtrue%2Centerprise-permission-management%3Dtrue%2Cmobile-layout-test%3Dfalse%2Cproject-permission-management%3Dtrue%2Cservice-exception-tips%3Dfalse%2Ctencent-cloud-object-storage%3Dtrue%2C5b585a51; enterprise_domain=xxx1; eid=5654521d-cf5a-4541-b0c3-a9f49f8ee571; clientId=yyyyyyyyyyyyyyyyyyyyyyyyyyy; XSRF-TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxx; cf=f18bc40cbc8a93d7f7fe94dd5daba14d; coding_demo_visited=1; c=auth-by-wechat%3Dtrue%2Cproject-permission-management%3Dtrue%2Centerprise-permission-management%3Dtrue%2C5c58505d; coding_api_document_production_session=eyJpdiI6IldrYmIrbsdflNsVVzg1xxxc1B2Umc9PSIsInZhbHVlIjoTWlVQWRxTERvUjFvUklmcThEKzBwSHFXaENjcW5lYm9pd1wvRHNid2d6aXFhTThNWXJvUGhVNWIrUjFqVGciLCJtYWMiOiI4OGJjZWEzYjU5YzU0M2ZkY2Q4OTc3ZmViZDc3NTMzMTgwZmI5OWZlOTJkYzgxODM1YWYzMDQ1MjNlZmQ5NWNkIn0%3D; _ga=GA1.2.72508426.1689557704; _gid=GA1.2.115254895.1689557704',
    'Origin': 'https://xxx1.coding.net',
    'Referer': 'https://xxx1.coding.net/p/jinglingfeng/requirements/issues/3438/detail/subissues/4534',
    'Sec-Ch-Ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': '"Windows"',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
    'X-Xsrf-Token': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}

# 打开Excel文件
workbook = openpyxl.load_workbook('../doc/data.xlsx')

# 选择工作表
worksheet = workbook['Sheet1']

# 循环读取每一行数据
for row in worksheet.iter_rows(min_row=5, values_only=True):
    # 获取列数据
    require_id = row[0]
    if require_id == None:
        break
    elif require_id == 4533:
        title = row[1] +'-'+ row[2]
    else:
        title = row[2]
    time = row[3] * 8
    coder = row[4]

    print(require_id,title,time,coder)
    data = {"iterationCode": 0, "parentCode": require_id, "name": title, "fileIds": [],
            "assignee": coder, "priority": 1, "dueDate": "2023-08-04", "workingHours": time,
            "issueTypeId": 8002879}

    # 将请求体转换为JSON格式
    json_data = json.dumps(data)

    # 发送POST请求,并包含请求头和请求体
    response = requests.post('https://xxx1.coding.net/api/project/10655274/issues/missions',
                             headers=headers,
                             data=json_data)

    # 获取响应内容
    content = response.json()

    # 打印响应内容
    print(content)


# 关闭Excel文件
workbook.close()
 

你可能感兴趣的:(excel,python,开发语言)