Content
# coze_to_xhs
- Get coze workflow data, use xhs_mcp_server to auto publish
- The program entry is auto_publish.py, which calls the coze workflow, outputs the required title, content, and images, and invokes xhs_mcp_server mcp for automated publishing.
# coze workflow run
- https://www.coze.cn/open/docs/developer_guides/workflow_run
- llm prompt
```text
# Role
You are a professional and experienced book summary generation expert, possessing a deep knowledge base and extensive practical experience. Based on the book title provided by the user, you can accurately and efficiently generate book summaries automatically. You are skilled in using DeepSeek technology for in-depth rewriting, following the AIDA model to create a strong sense of objectivity, immersion, and empathy. You carefully extract three high-quality summaries, crafting titles and content that align with the style of Xiaohongshu (Little Red Book). Each segment of content is strictly controlled to around 300 words, presenting the core points of the book comprehensively and concisely. The rewritten Xiaohongshu titles and content should be output separately, with each complete sentence displayed on a new line. Additionally, you must ensure the accuracy of information sources, utilizing search tools to obtain the latest and most reliable information when relevant knowledge is involved.
## Skills
### Skill 1: Accurate Generation of Book Summaries
1. Conduct an in-depth analysis of the user's input book title, considering multiple dimensions such as themes, plots, characters, and writing styles. Utilize advanced text analysis methods and professional tools to automatically generate high-quality book summaries.
2. The generated book summaries accurately encompass the core viewpoints, key plots, important character relationships, and other critical information of the book, ensuring that the content is complete, logically clear, and well-organized.
### Skill 2: In-depth Rewriting and Style Shaping
1. Proficiently use the DeepSeek tool to comprehensively and systematically rewrite the generated book excerpts, extracting 3 logically coherent, focused, and well-structured summaries.
2. Closely align with the stylistic characteristics of the Xiaohongshu platform, meticulously crafting the language style (such as lively, playful, and engaging), formatting (reasonable paragraphing, use of emojis, etc.), and reimagining highly attractive titles and content that conform to Xiaohongshu's style. Each paragraph should be around 300 words; if the content is less than 300 words, leverage linguistic talent to expand it, accurately conveying the essence of the book. Each paragraph should include a summary title of about 10 words, while also generating a concise and powerful overall title that aligns with Xiaohongshu's style.
### Skill 3: In-Depth Exploration of Author Profiles
1. Utilize the precise search function to deeply explore the author profile information of books, ensuring that the information is accurate, complete, and timely.
2. Carefully filter and organize the searched author profiles, extracting key and valuable information to present to users in a concise, clear, and engaging manner.
3. Use image search tools to find 3 image URLs related to the book title.
### Skill 4: Guiding Readers to Comment
1. Pose 2 questions to encourage readers to comment, each question around 30 words.
## Restrictions:
- Only perform operations related to generating book excerpts, rewriting, and author profile extraction based on the book title provided by the user, without addressing unrelated topics.
- The output content must be strictly organized according to the required format, with titles and each paragraph displayed on separate lines.
- Each paragraph of the book excerpt must be strictly controlled to around 300 words; if it is less than 300 words, it should be expanded. The main title should be concise and highly summarize the overall content.
- When obtaining information through search tools, ensure that the sources are reliable and authoritative.
- Assign the main title to the title variable, delete the main title from other content and assign it to the content variable, and output image address information to images.
- The output for title/content/images must conform to JSON format.
- Remove special characters (such as 📖, ✨, 📚, 🎓, etc.) from content.
- All formats must comply with JSON format for downstream use.
- Responses must utilize search or browsing tools to obtain information, ensuring the accuracy of the sources.
# xhs_mcp_server
- https://pypi.org/project/xhs-mcp-server/
# ref
- https://www.modelscope.cn/mcp/servers/@XGenerationLab/xhs_mcp_server Xiaohongshu MCP Publisher
- https://www.modelscope.cn/learn/1205?pid=1204 Use Qwen3 + MCPs to achieve AI automatic publishing of Xiaohongshu notes! Supports both images and videos.
# Get WeChat Book Rankings (wx_bd_json.py)
- Call https://weread.qq.com/web/bookListInCategory/all?maxIndex={maxIndex}&rank={rank} to parse the required book information
```python
import time
import requests
def parse_book_data(url_template: str, start_max_index: int = 0, start_rank: int = 1) -> list:
"""
Loop to parse the JSON data returned by the API, extracting book titles and author information
:param url_template: API URL template (must include {maxIndex} and {rank} placeholders)
:param start_max_index: Starting maxIndex value (default 0)
:param start_rank: Starting rank value (default 1)
:return: A list containing book titles and authors
"""
all_books = []
current_max_index = start_max_index
current_rank = start_rank
has_more = 1 # Control flag for the loop
while has_more < 10:
# Construct the current request URL
current_url = url_template.format(maxIndex=current_max_index, rank=current_rank)
try:
response = requests.get(current_url)
response.raise_for_status() # Raise HTTP errors
data = response.json()
# Parse JSON data
books = data.get("books", [])
if not books:
break # Terminate early if no data
# Extract book titles and authors
for book in books:
book_info = book.get("bookInfo", {})
title = book_info.get("title", "Unknown Title")
author = book_info.get("author", "Unknown Author")
all_books.append({"书名": title, "作者": author})
# Update parameters for the next page
current_max_index += len(books) # maxIndex is usually the starting index for the next page
current_rank = 1 # rank is the starting rank for the next page
has_more += 1 # Check if there is more data (1 means there is)
time.sleep(5)
print(
f"Retrieved {len(books)} records, current maxIndex={current_max_index - len(books)}, rank=1, has_more={has_more}")
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
break
except KeyError as e:
print(f"JSON structure error, missing key: {e}")
break
return all_books
if __name__ == "__main__":
# API URL template (Note: Ensure this URL is valid and supports maxIndex and rank parameters when in use)
API_URL_TEMPLATE = "https://weread.qq.com/web/bookListInCategory/all?maxIndex={maxIndex}&rank={rank}"
# Start parsing data
books_data = parse_book_data(API_URL_TEMPLATE)
# Output results
print(f"\nA total of {len(books_data)} books parsed:")
for idx, book in enumerate(books_data, 1):
print(f"- {book['书名']} {book['作者']}")
```
# example
- config.yaml
```yaml
books:
- Cognitive Awakening: The Driving Force for Self-Change by Zhou Ling
phone_number: xxxxxxxxxx
cookie_path: /Users/linear/myown/cookie
agent_id: xxxxxxxxxx
workflow_id: xxxxxxxxxx
api_key: xxxxxxxxxx
multi_pic: false
```
- agent_results.json
```json
{
"book_title": "Cognitive Awakening: The Driving Force for Self-Change by Zhou Ling",
"result": "{\"content_type\":1,\"data\":\"{\\n \\\"title\\\": \\\"Cognitive Awakening: Finding the Key to Self-Change\\\",\\n \\\"content\\\": \\\"Main Title: Cognitive Awakening: Finding the Key to Self-Change\\n\\nSubheading: Analyzing Thinking Patterns\\nCognitive Awakening delves into thinking patterns such as “brain structure, subconscious, and metacognition.” Humans have instinctual brains, emotional brains, and rational brains; the first two lead us to have a short-sighted nature and a tendency for instant gratification, such as finding it hard to resist the temptation of smartphones, which is not merely a lack of willpower. Metacognition allows us to reflect on our own thoughts and actions, like reviewing daily events that touch us, maintaining clarity through reflection and connections, and correcting unwise thoughts.\\n\\nSubheading: Following the Laws of Things\\nThe book elaborates on the laws of things such as “deep learning, connections, and feedback,” which help us achieve our goals. Learning cannot be limited to listening and reading; we must enhance retention through discussions and teaching others. After reading a book, we should express the content in our own words, reflecting on our experiences and connecting related matters. Growth in ability has comfort zones, stretching zones, and difficulty zones; we should be at the edge of the comfort zone, reading books that are slightly challenging.\\n\\nSubheading: Alleviating Anxiety and Cultivating Patience\\nAnxiety arises from a large gap between desire and ability, coupled with a lack of patience. To alleviate anxiety, one must understand the growth path of “learning - thinking - acting - changing,” seeking change through reading rather than merely quantity. Cultivating patience requires accepting oneself, letting go of burdens to face one’s nature; learning to delay gratification, transforming confrontation into communication; changing perspectives when facing difficulties, and giving meaning to actions.\\n\\nThe author Zhou Ling is a writer, self-media person, and mental explorer. His articles are deep yet easy to understand, often praised by readers as a breath of fresh air, and have been reprinted by various media outlets including the official Weibo of the People’s Daily.\\n\\nInteractive Questions:\\n1. Have you ever regretted something in life due to the dominance of your instinctual and emotional brains?\\n2. After trying the methods in the book, what noticeable changes have you experienced in cultivating patience?\\\",\\n \\\"images\\\": [\\\"https://img.alicdn.com/i3/1049653664/O1CN011p1JPT1cw9vtOhEge_!!1049653664.jpg\\\",\\\"https://qny.smzdm.com/202405/14/6642c618984523074.jpg_a200.jpg\\\",\\\"https://tu.tuibook.com/2024/02/20240202082641802.jpeg\\\"]\\n}\",\"original_result\":null,\"type_for_model\":2}"
}
```
- log
```text
/usr/local/opt/python@3.11/bin/python3.11 /Users/linear/myown/code/coze_to_xhs/src/audo_publish.py
Starting to process book: Cognitive Awakening: The Driving Force for Self-Change by Zhou Ling
HTTP Request: POST https://api.coze.cn/v1/workflow/run "HTTP/1.1 200 OK"
workflow.data {"content_type":1,"data":"{\n \"title\": \"Cognitive Awakening: Finding the Key to Self-Change\",\n \"content\": \"Main Title: Cognitive Awakening: Finding the Key to Self-Change\\n\\nSubheading: Analyzing Thinking Patterns\\nCognitive Awakening delves into thinking patterns such as “brain structure, subconscious, and metacognition.” Humans have instinctual brains, emotional brains, and rational brains; the first two lead us to have a short-sighted nature and a tendency for instant gratification, such as finding it hard to resist the temptation of smartphones, which is not merely a lack of willpower. Metacognition allows us to reflect on our own thoughts and actions, like reviewing daily events that touch us, maintaining clarity through reflection and connections, and correcting unwise thoughts.\\n\\nSubheading: Following the Laws of Things\\nThe book elaborates on the laws of things such as “deep learning, connections, and feedback,” which help us achieve our goals. Learning cannot be limited to listening and reading; we must enhance retention through discussions and teaching others. After reading a book, we should express the content in our own words, reflecting on our experiences and connecting related matters. Growth in ability has comfort zones, stretching zones, and difficulty zones; we should be at the edge of the comfort zone, reading books that are slightly challenging.\\n\\nSubheading: Alleviating Anxiety and Cultivating Patience\\nAnxiety arises from a large gap between desire and ability, coupled with a lack of patience. To alleviate anxiety, one must understand the growth path of “learning - thinking - acting - changing,” seeking change through reading rather than merely quantity. Cultivating patience requires accepting oneself, letting go of burdens to face one’s nature; learning to delay gratification, transforming confrontation into communication; changing perspectives when facing difficulties, and giving meaning to actions.\\n\\nThe author Zhou Ling is a writer, self-media person, and mental explorer. His articles are deep yet easy to understand, often praised by readers as a breath of fresh air, and have been reprinted by various media outlets including the official Weibo of the People’s Daily.\\n\\nInteractive Questions:\\n1. Have you ever regretted something in life due to the dominance of your instinctual and emotional brains?\\n2. After trying the methods in the book, what noticeable changes have you experienced in cultivating patience?\",\n \"images\": [\"https://img.alicdn.com/i3/1049653664/O1CN011p1JPT1cw9vtOhEge_!!1049653664.jpg\",\"https://qny.smzdm.com/202405/14/6642c618984523074.jpg_a200.jpg\",\"https://tu.tuibook.com/2024/02/20240202082641802.jpeg\"]\n}","original_result":null,"type_for_model":2} https://www.coze.cn/work_flow?execute_id=7505605457399808037&space_id=7493495980332285988&workflow_id=7505245815179804691&execute_mode=2 None
Saved the result of Cognitive Awakening: The Driving Force for Self-Change by Zhou Ling to agent_results.json
title parse after Cognitive Awakening: Finding the Key to Self-Change
content parse after
Analyzing Thinking Patterns
Cognitive Awakening delves into thinking patterns such as “brain structure, subconscious, and metacognition.” Humans have instinctual brains, emotional brains, and rational brains; the first two lead us to have a short-sighted nature and a tendency for instant gratification, such as finding it hard to resist the temptation of smartphones, which is not merely a lack of willpower. Metacognition allows us to reflect on our own thoughts and actions, like reviewing daily events that touch us, maintaining clarity through reflection and connections, and correcting unwise thoughts.
Following the Laws of Things
The book elaborates on the laws of things such as “deep learning, connections, and feedback,” which help us achieve our goals. Learning cannot be limited to listening and reading; we must enhance retention through discussions and teaching others. After reading a book, we should express the content in our own words, reflecting on our experiences and connecting related matters. Growth in ability has comfort zones, stretching zones, and difficulty zones; we should be at the edge of the comfort zone, reading books that are slightly challenging.
Alleviating Anxiety and Cultivating Patience
Anxiety arises from a large gap between desire and ability, coupled with a lack of patience. To alleviate anxiety, one must understand the growth path of “learning - thinking - acting - changing,” seeking change through reading rather than merely quantity. Cultivating patience requires accepting oneself, letting go of burdens to face one’s nature; learning to delay gratification, transforming confrontation into communication; changing perspectives when facing difficulties, and giving meaning to actions.
The author Zhou Ling is a writer, self-media person, and mental explorer. His articles are deep yet easy to understand, often praised by readers as a breath of fresh air, and have been reprinted by various media outlets including the official Weibo of the People’s Daily.
Interactive Questions:
1. Have you ever regretted something in life due to the dominance of your instinctual and emotional brains?
2. After trying the methods in the book, what noticeable changes have you experienced in cultivating patience?
images parse after ['https://img.alicdn.com/i3/1049653664/O1CN011p1JPT1cw9vtOhEge_!!1049653664.jpg', 'https://qny.smzdm.com/202405/14/6642c618984523074.jpg_a200.jpg', 'https://tu.tuibook.com/2024/02/20240202082641802.jpeg']
Publishing to Xiaohongshu: Cognitive Awakening: Finding the Key to Self-Change
Using phone number: xxxxxxxxxxx
Using cookie file: /Users/linear/myown/cookie
Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json)
download_image error 420 Client Error: for url: https://img.alicdn.com/i3/1049653664/O1CN011p1JPT1cw9vtOhEge_!!1049653664.jpg
download_image error HTTPSConnectionPool(host='tu.tuibook.com', port=443): Max retries exceeded with url: /2024/02/20240202082641802.jpeg (Caused by SSLError(SSLEOFError(8, '[SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1016)')))
Analyzing Thinking Patterns
Cognitive Awakening delves into thinking patterns such as “brain structure, subconscious, and metacognition.” Humans have instinctual brains, emotional brains, and rational brains; the first two lead us to have a short-sighted nature and a tendency for instant gratification, such as finding it hard to resist the temptation of smartphones, which is not merely a lack of willpower. Metacognition allows us to reflect on our own thoughts and actions, like reviewing daily events that touch us, maintaining clarity through reflection and connections, and correcting unwise thoughts.
Following the Laws of Things
The book elaborates on the laws of things such as “deep learning, connections, and feedback,” which help us achieve our goals. Learning cannot be limited to listening and reading; we must enhance retention through discussions and teaching others. After reading a book, we should express the content in our own words, reflecting on our experiences and connecting related matters. Growth in ability has comfort zones, stretching zones, and difficulty zones; we should be at the edge of the comfort zone, reading books that are slightly challenging.
Alleviating Anxiety and Cultivating Patience
Anxiety arises from a large gap between desire and ability, coupled with a lack of patience. To alleviate anxiety, one must understand the growth path of “learning - thinking - acting - changing,” seeking change through reading rather than merely quantity. Cultivating patience requires accepting oneself, letting go of burdens to face one’s nature; learning to delay gratification, transforming confrontation into communication; changing perspectives when facing difficulties, and giving meaning to actions.
The author Zhou Ling is a writer, self-media person, and mental explorer. His articles are deep yet easy to understand, often praised by readers as a breath of fresh air, and have been reprinted by various media outlets including the official Weibo of the People’s Daily.
Interactive Questions:
1. Have you ever regretted something in life due to the dominance of your instinctual and emotional brains?
2. After trying the methods in the book, what noticeable changes have you experienced in cultivating patience?
Publishing successful
Publishing completed, result: True res: Publishing successful
sleep a while...sleep_count: 1
sleep a while...sleep_count: 2
sleep a while...sleep_count: 3
sleep a while...sleep_count: 4
sleep a while...sleep_count: 5
sleep a while...sleep_count: 6
sleep a while...sleep_count: 7
sleep a while...sleep_count: 8
sleep a while...sleep_count: 9
sleep a while...sleep_count: 10
sleep a while...sleep_count: 11
sleep a while...sleep_count: 12
sleep a while...sleep_count: 13
sleep a while...sleep_count: 14
sleep a while...sleep_count: 15
sleep a while...sleep_count: 16
sleep a while...sleep_count: 17
sleep a while...sleep_count: 18
sleep a while...sleep_count: 19
sleep a while...sleep_count: 20
sleep a while...sleep_count: 21
sleep a while...sleep_count: 22
sleep a while...sleep_count: 23
sleep a while...sleep_count: 24
sleep a while...sleep_count: 25
sleep a while...sleep_count: 26
sleep a while...sleep_count: 27
sleep a while...sleep_count: 28
sleep a while...sleep_count: 29
sleep a while...sleep_count: 30
sleep a while...sleep_count: 31
sleep a while...sleep_count: 32
sleep a while...sleep_count: 33
sleep a while...sleep_count: 34
sleep a while...sleep_count: 35
sleep a while...sleep_count: 36
sleep a while...sleep_count: 37
sleep a while...sleep_count: 38
sleep a while...sleep_count: 39
sleep a while...sleep_count: 40
sleep a while...sleep_count: 41
sleep a while...sleep_count: 42
sleep a while...sleep_count: 43
sleep a while...sleep_count: 44
sleep a while...sleep_count: 45
sleep a while...sleep_count: 46
sleep a while...sleep_count: 47
sleep a while...sleep_count: 48
sleep a while...sleep_count: 49
sleep a while...sleep_count: 50
sleep a while...sleep_count: 51
sleep a while...sleep_count: 52
sleep a while...sleep_count: 53
sleep a while...sleep_count: 54
sleep a while...sleep_count: 55
sleep a while...sleep_count: 56
sleep a while...sleep_count: 57
sleep a while...sleep_count: 58
sleep a while...sleep_count: 59
sleep a while...sleep_count: 60
log_content:
Processing book: Cognitive Awakening: The Driving Force for Self-Change by Zhou Ling
Agent result saved successfully
Xiaohongshu publishing successful
All processing completed, log saved to publish_log.txt
Process finished with exit code 0
```
Connection Info
You Might Also Like
markitdown
Python tool for converting files and office documents to Markdown.
Fetch
Retrieve and process content from web pages by converting HTML into markdown format.
chatbox
User-friendly Desktop Client App for AI Models/LLMs (GPT, Claude, Gemini, Ollama...)
continue
Continue is an open-source project for seamless server management.
oh-my-opencode
Background agents · Curated agents like oracle, librarians, frontend...
semantic-kernel
Build and deploy intelligent AI agents with Semantic Kernel's orchestration...