Backend Development 4 min read

Implementing a WeChat Daily Sentence Template Message with Python and Cron

This tutorial explains how to use WeChat's template message API together with the iciba daily‑sentence service, set up a Python script on an Alibaba Cloud Linux server, configure the template in the public platform, and schedule automatic delivery via a daily cron job.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Implementing a WeChat Daily Sentence Template Message with Python and Cron

WeChat development has long provided a powerful template message interface that can push custom messages to users based on their OpenID, enabling server‑side notifications such as a daily "good morning" message.

Experiment environment : an Alibaba Cloud Linux server running Python, and the iciba daily‑sentence API (http://open.iciba.com/dsapi/, GET request returning JSON with fields like content , note , and translation ).

The API response format is JSON; a typical response includes the sentence, its source, and translation. Example request and response screenshots are shown in the original article.

Code examples for Python 2, Python 3, and PHP are provided (images). The template content to be sent is defined as:

{{content.DATA}}<br/>{{note.DATA}}<br/>{{translation.DATA}}

In the WeChat public platform test account, create a new template titled "每日一句" (Daily Sentence) and paste the above placeholders as the template body, then save the template ID for later use.

Retrieve the test account's appid and appsecret from the platform, and scan the test QR code to add the test account as a follower (note that this is a test WeChat ID, not a real personal account).

The complete program source is hosted on GitHub at https://github.com/varlemon/wechat-iciba-everyday . Only four configuration points need to be edited (shown in the Python 2 implementation screenshot).

To deploy, run the script on the Linux server and set up a cron job:

crontab -e

Add the following line to execute the script every day at 06:00:

0 6 * * * python /root/python/iciba/main-v1.0.py

Verify the schedule with:

crontab -l

After deployment, the script sends the daily sentence to the test WeChat account; screenshots show the received message on a mobile device.

Thus, the program is fully deployed and will deliver the daily sentence each morning at 6 am.

backendAPICronWeChatTemplate Message
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.