Answers

How do I save Weibo hot search every hour to build a history?

Short answer

Call Weibo hot search once an hour and append every row, stamped with the fetch time, to a file or table. Each snapshot is one call at $0.002, so a month of hourly snapshots (720 calls) costs $1.44. The API keeps no history for you, so your archive starts on the day you start collecting.

A media researcher measuring how long topics stay on the board, or a brand team that wants proof its campaign peaked at number 3 last Tuesday night, needs something Weibo does not offer: the board as it looked at past moments. The practical answer is to take the snapshots yourself. One call to Weibo hot search returns the whole board, so an hourly cron job builds a clean time series with about twenty lines of code.

Cost by sampling rate

Sampling Calls a month Cost a month
Every hour 720 $1.44
Every 30 minutes 1,440 $2.88
Every 10 minutes 4,320 $8.64

Hourly is enough to measure how many hours a topic lasted and its peak rank. Topics that flash up and vanish within twenty minutes only show up at a 10-minute rate.

A script for cron

import csv, os, datetime, requests

hour = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H")
r = requests.get(
    "https://api.okdata.online/v1/weibo/trends/list",
    headers={
        "Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}",
        "Idempotency-Key": f"weibo-hot-{hour}",
    },
    params={"fields": "rank,name,heat"},
    timeout=30,
).json()
if r["code"] != "ok":
    raise SystemExit(f"{r['code']}: {r['message']}")

taken = r["meta"]["fetched_at"]
with open("weibo_hot.csv", "a", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    for row in r["data"]["items"]:
        w.writerow([taken, row["rank"], row["name"], row["heat"]])

Run it with a crontab line such as 0 * * * * python3 /opt/weibo_hot.py. The idempotency key is built from the hour, so if cron fires twice in the same hour the second run replays the stored board and costs nothing.

Things that trip people up

  • Ranks skip where a promoted row was removed. A gap in the ranks is not missing data.
  • heat can be null for some rows. Keep the row; the rank still counts.
  • If a call fails, for example with upstream_busy, nothing is charged. Retry a minute later instead of losing the hour, and log any hour you never got so gaps are visible in the analysis.
  • Topic names change slightly as they evolve. Match them loosely when you count how long one topic lasted.

When another route is better

  • Need boards from before you started? Snapshots cannot backfill. Several open-source GitHub projects have committed the board to a repository for years; check whether their dates and sampling fit your study.
  • Social listening suites sell historical hot search data with charts. They are worth paying for when you need years of backfill and no code at all.

More ideas for working with boards across platforms are on trend research, and every price is on the pricing page.

Updated