reposync/pr_sync/get_gitlink_pr_list.py

44 lines
1.5 KiB
Python

import requests
import mysql.connector
# 连接到MySQL数据库
conn = mysql.connector.connect(
host="localhost",
user="root",
password="185102xmy",
database="db1"
)
cursor = conn.cursor()
cursor.execute('DROP TABLE IF EXISTS gitlink_pr_list')
cursor.execute('''CREATE TABLE IF NOT EXISTS gitlink_pr_list
(id INT AUTO_INCREMENT PRIMARY KEY, number VARCHAR(10), state VARCHAR(15), title VARCHAR(100), body VARCHAR(1000), head VARCHAR(15), base VARCHAR(15))''')
url = "https://gitlink.org.cn/api/v1/xumingyang21/reposyncer2/pulls.json?keyword&status&priority_id&issue_tag_id&version_id&reviewer_id&assign_user_id&sort_by&sort_direction"
payload={}
access_token = 'I9uyRzjEIObdgsD8fegdQoN2d3p3cU_7_uaNGV03S_Q'
headers = {
'Authorization': f'Bearer {access_token}', # 使用 Bearer 标记
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}
response = requests.request("GET", url, headers=headers, data=payload)
data = response.json()
for pr_info in data['pulls']:
print('id:', pr_info['id'])
print('state:', pr_info['status'])
print('title:', pr_info['title'])
print('body:', pr_info['body'])
print('head:', pr_info['head'])
print('base:', pr_info['base'])
cursor.execute(
'INSERT INTO gitlink_pr_list (number, state, title, body, head, base) VALUES (%s, %s, %s, %s, %s, %s)',
(pr_info['id'], pr_info['status'], pr_info['title'], pr_info['body'], pr_info['head'], pr_info['base']))
print(response.text)
# 提交事务
conn.commit()
# 关闭游标和连接
cursor.close()
conn.close()