import os import html2text import requests wordpress_url = "https://ivampiresp.com" api_url = wordpress_url + "/wp-json/wp/v2/posts" leaf_api_url = "http://localhost:8080/api/documents" libraryId = 1 jwt = os.getenv("JWT") # 获取全部文章 res = requests.get(api_url) res_json = res.json() for i in range(len(res_json)): title = res_json[i]["title"]["rendered"] post_id = res_json[i]["id"] url = res_json[i]["link"] text = html2text.HTML2Text().handle(res_json[i]["content"]["rendered"]) content = f""" 文章ID: {post_id} 链接: {url} --- {text} """ result = requests.post(leaf_api_url, json={ "Title": title, "Content": content, "LibraryId": libraryId }, headers={ # "Authorization": f"Bearer {jwt}" "X-Jwt-Payload": f"{jwt}" }) print(result.json())