Automating Public Opinion Monitoring with Scheduled Tasks and WeChat Notifications

A public wager from 2015 resurfaced when a major technological milestone was achieved in 2022, seven years ahead of the predicted timeline. The original bet involved the launch of an aircarft carrier equipped with electromagnetic catapults. When the Fujian was launched with this specific technology, the original poster acknowledged the loss and fulfilled the bet by addressing the community with the agreed-upon term of address.

To fully analyze the public reaction, specifically the comment section of the original post, a technical approach was taken to scrape and monitor the data. Initially, a script was used to pull all existing comments. However, to keep up with real-time updates, the process was iterated to include a scheduled monitoring system.

Data Synchronization Strategy

Instead of a one-time scrape, a polling mechanism was implemented. The goal was to detect new comments without repeatedly downloading the entire dataset.

  1. Identify the Endpoint: Locate the API responsible for sorting comments by time (newest first).
  2. Database Check: Query the local database to find the timestamp of the most recent comment stored.
  3. Comparison Logic: Fetch the latest comments from the API. Compare the timestamp of the incoming data with the timestamp stored in the database.
  4. Update Process: If the API returns a comment newer than the database record, save it. Continue this process until a comment timestamp matches or is older than the latest record in the daatbase.

This ensures that only incremental updates are processed.

Real-time Notification System

To avoid manually checking the database, a push notification system was integrated using the WeChat Official Account interface.

1. Obtaining Credentials Access the WeChat Sandbox environment to obtain a test account. The appID and appsecret are required to generate an access_token.

2. Template Message Setup In the sandbox interface, enable the "Template Message" permission. Create a template with variables for the comment content and author.

3. Implementation Logic The following Python-style pseudocode demonstrates the process of checking for new data and triggering a notification:

def monitor_and_notify():
    latest_local_time = database.get_latest_timestamp()
    api_response = wechat_api.fetch_latest_comments()

    for comment in api_response:
        if comment['timestamp'] > latest_local_time:
            database.save(comment)
            
            # Filter for specific user (e.g., the original poster)
            if comment['author_id'] == 'target_user_123':
                payload = {
                    "touser": "user_open_id",
                    "template_id": "template_123",
                    "data": {
                        "first": {"value": "New comment detected!"},
                        "content": {"value": comment['text']},
                        "author": {"value": comment['author_name']}
                    }
                }
                wechat_api.send_message(payload)
        else:
            break

4. Execution A scheduler runs the monitor_and_notify function every 10 minutes. This allows for near real-time tracking of specific users' replies within a high-traffic thread.

Note that the access_token has a validity period of 7200 seconds; therefore, the implementation must include a mechanism to refresh the token periodically before it expires.

Tags: web scraping API Integration wechat development python automation

Posted on Mon, 06 Jul 2026 16:57:22 +0000 by qartis