Skip to navigation

How can Python connect WeChat article lists and statistics for content review?

To review an official account’s content with Python, save one directory page with wechat_mp.v2.fetch_account_articles, select the relevant articles, then save each selected article’s statistics with wechat_mp.v2.fetch_article_stats and convert the saved statistics to CSV with the existing wechat_metrics.py exporter. For example, to study how an industry account explains product tutorials, first list what the account published, then select the tutorial articles and inspect their reads and engagement at the current observation time. The deliverable is a selected article list, the metrics, the source evidence and questions for further reading.

If you already know the article URLs, go directly to statistics in step 4. Start with the directory in step 2 when you need the account’s recent subject coverage.

1. Confirm the account and review question

Fix the target account and a review question such as “which usage steps do recent tutorials explain?” Reuse a verified username. If you only have one article from the account, follow the account-identifier handoff to obtain data.content.user_name. Use the display name to verify the source; do not enter the display name as the account identifier.

wechat_mp.v2.fetch_account_articles accepts gh_…, gh_…@app and custom WeChat IDs as username. The existing history processor in the article directory workflow (step 3) accepts canonical gh_ identifiers only, so use a gh_ identifier when you plan to continue with that processor. Other valid forms still save directory originals; record the compatibility difference with the saved files.

One directory page plus one statistics request for each of three tutorials is at most four requests. Add account discovery, extra history pages or article bodies only when the review needs them. See current pricing.

2. Save one batch with Python

Use the Python 3 standard library and set BEATAPI_API_KEY in your local environment. Save the script below as mp_read.py. Each run of mp_read.py retrieves one directory page (list) or one article’s standard statistics (stats) into a new directory.

import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
if len(sys.argv) != 4 or sys.argv[1] not in {"list", "stats"}:
raise SystemExit("Usage: python3 mp_read.py list|stats VALUE NEW_DIRECTORY")
mode, value, directory = sys.argv[1:]
if not value.strip():
raise SystemExit("Supply a verified account username or article URL")
key = os.environ.get("BEATAPI_API_KEY")
if not key:
raise SystemExit("Set BEATAPI_API_KEY in your local environment")
if mode == "list":
action = "wechat_mp.v2.fetch_account_articles"
params = {"username": value, "offset": "", "item_show_type": 0, "raw": False}
else:
action = "wechat_mp.v2.fetch_article_stats"
params = {"url": value, "raw": True}
body = {"action": action, "params": params}
out = Path(directory)
out.mkdir(parents=True, exist_ok=False)
(out / "request.json").write_text(json.dumps(body, ensure_ascii=False, indent=2), encoding="utf-8")
started = datetime.now(timezone.utc).isoformat()
(out / "attempt.json").write_text(json.dumps({"started_at": started, "action": action}), encoding="utf-8")
request = Request("https://api.beatapi.io/v1/social-data/call",
data=json.dumps(body).encode("utf-8"), method="POST",
headers={"Authorization": "Bearer " + key, "Content-Type": "application/json"})
try:
with urlopen(request, timeout=60) as response:
status, raw = response.status, response.read()
except HTTPError as error:
status, raw = error.code, error.read()
except URLError:
(out / "transport-error.json").write_text(json.dumps({"outcome": "unknown", "action": action}), encoding="utf-8")
raise SystemExit("No final response saved; review the attempted request before repeating")
(out / "response.json").write_bytes(raw)
(out / "call.json").write_text(json.dumps({"action": action, "params": params,
"http_status": status, "started_at": started,
"finished_at": datetime.now(timezone.utc).isoformat(),
"response_file": "response.json", "platform_review": "required"},
ensure_ascii=False, indent=2), encoding="utf-8")
try:
payload = json.loads(raw)
except (ValueError, UnicodeError):
raise SystemExit("Saved a non-JSON response; inspect response.json")
if status != 200 or not isinstance(payload, dict) or payload.get("status") != "succeeded" or payload.get("error") is not None or payload.get("action") != action:
raise SystemExit("Saved a failed or unexpected response; inspect response.json")
print("Saved response for platform-content review: " + str(out / "response.json"))

Retrieve the target account’s directory:

python3 mp_read.py list '<confirmed_username>' mp-list-01

The list mode sends raw:false, article tab 0 and an empty offset, matching the existing directory workflow. page_size may be ignored, so do not plan on a fixed twenty articles per page. The original response is saved in response.json; call.json keeps the request conditions and times for reuse.

3. Select the articles worth reviewing

  1. Confirm that response.json shows the intended account and tab.
  2. Read the actual titles, summaries, URLs and publication times.
  3. Separate tutorials, promotional material and republications.
  4. Record a reason for selecting or excluding each article, which gives you a fixed review list.

For example, an installation guide, a daily-operation guide and a troubleshooting article serve different reader needs even though all three are tutorials. The directory supplies leads; retrieve the article bodies when you discuss specific writing choices.

For more history, pass the actual next_offset through the article directory workflow; do not use an article count as offset. The article directory workflow provides directory CSV and history-state processing. mp_read.py saves first batches only; the article directory workflow handles continuation.

4. Retrieve statistics for selected articles

After confirming an article URL, run:

python3 mp_read.py stats '<confirmed_article_url>' mp-stats-01

Use a new output directory for each article. wechat_mp.v2.fetch_article_stats accepts public short links and long __biz links. Keep raw:true so that display and retrieval states are saved alongside the values. For metric meanings and how to read a current snapshot, see campaign article review.

Link directory entries and statistics through the actual requested URLs. Keep separate identities for articles with the same title. A later observation of the same article keeps its own time and does not replace the earlier snapshot.

5. Reuse CSV processing on saved responses

Save wechat_metrics.py from the reading and engagement FAQ. In stats-pages.json, create one entry for each actual statistics response:

  1. Copy http_status from the response’s call.json.
  2. Use finished_at from call.json as collected_at.
  3. Set response_file relative to the directory that holds stats-pages.json.

Replace the example values below:

[
{
"action": "wechat_mp.v2.fetch_article_stats",
"params": {"url": "https://mp.weixin.qq.com/s/example", "raw": true},
"http_status": 200,
"collected_at": "2026-11-17T08:00:00+08:00",
"response_file": "mp-stats-01/response.json"
}
]

Convert the saved responses locally:

python3 wechat_metrics.py stats-pages.json mp-review-01

metrics.csv is a long table with one row per article and metric, so count articles separately. URLs and source references link each row to an article; titles, content purposes and selection reasons come from the directory and your selection sheet. To join article bodies with statistics, use the source/stat join, which works in batches of up to five article pairs.

6. Turn the metric table into a review

Before investigating differences, establish each article’s purpose, accumulation time and data state. Keep integers, display thresholds, missing values and failures distinct. Today’s statistics describe a current observation; a seventh-day comparison needs statistics saved on the seventh day.

Deliver the directory, the selection reasons, the metric table, the originals and three to five specific review questions, such as “does the installation guide explain preparation clearly?” and “what structure makes the operation article useful to revisit?” Attach evidence and a next step to each question. Counts point to material worth reading; the article content supports the explanation.

For example, a batch contains a quickstart and a legacy migration guide. Interpret each article’s metrics in light of the article’s purpose. Add “Which introduction makes the version requirements clear?” to the review, and attach the saved metrics file and the article URLs so a teammate can pick up the question.

To hand the review to an assistant connected to BeatAPI, use this instruction:

Study recent tutorials from the target account using the verified identifier. Inspect one directory page and select three relevant articles. Save standard statistics for the three articles and reuse the existing exporter. Explain differences through purpose, age and state, then list questions for reading the bodies. Deliver article selection reasons, metrics and sources with actual coverage.