How to Build a Python WeChat Bot for Timed Girlfriend Messages

Learn how to use Python's wxpy library to create a WeChat bot that automatically sends personalized greetings, holiday wishes, birthday messages, and English learning prompts to your girlfriend at scheduled times, while also performing simple sentiment analysis of her replies.

dbaplus Community
dbaplus Community
dbaplus Community
How to Build a Python WeChat Bot for Timed Girlfriend Messages

Purpose

Automates relationship care using Python and the wxpy library to send scheduled WeChat messages (morning wake‑up, lunch, dinner, bedtime, holiday and birthday greetings) and to fetch a daily English learning snippet. The bot also performs sentiment analysis on incoming messages.

Configuration File

All customizable parameters are stored in config.ini. The script reads the file with configparser and extracts values such as the girlfriend's WeChat name, scheduled times, birthday, and flags for English learning and emoji usage.

cf = configparser.ConfigParser()
cf.read("./config.ini", encoding='UTF-8')
my_lady_wechat_name = cf.get("configuration", "my_lady_wechat_name")
say_good_morning = cf.get("configuration", "say_good_morning")
say_good_lunch = cf.get("configuration", "say_good_lunch")
say_good_dinner = cf.get("configuration", "say_good_dinner")
say_good_dream = cf.get("configuration", "say_good_dream")
birthday_month = cf.get("configuration", "birthday_month")
birthday_day = cf.get("configuration", "birthday_day")
flag_learn_english = cf.get("configuration", "flag_learn_english") == '1'
flag_wx_emoj = cf.get("configuration", "flag_wx_emoj") == '1'

Message Templates

Greeting sentences are stored as plain‑text files under remind_sentence/. The script loads each list at runtime. Emoji strings are defined in a single line and split into an array.

with open("./remind_sentence/sentence_good_morning.txt", "r", encoding='UTF-8') as f:
    str_list_good_morning = f.readlines()
with open("./remind_sentence/sentence_good_lunch.txt", "r", encoding='UTF-8') as f:
    str_list_good_lunch = f.readlines()
with open("./remind_sentence/sentence_good_dinner.txt", "r", encoding='UTF-8') as f:
    str_list_good_dinner = f.readlines()
with open("./remind_sentence/sentence_good_dream.txt", "r", encoding='UTF-8') as f:
    str_list_good_dream = f.readlines()
str_emoj = "(•‾̑⌣‾̑•)✧˖°----(๑´ڡ`๑)----(๑¯ิε ¯ิ๑)----(๑•́ ₃ •̀๑)----( ∙̆ .̯ ∙̆ )"
str_list_emoj = str_emoj.split('----')

Holiday and Birthday Messages

Special messages for Valentine’s Day, Women’s Day, Christmas Eve, Christmas and birthday are read from the configuration.

str_Valentine = cf.get("configuration", "str_Valentine")
str_Women = cf.get("configuration", "str_Women")
str_Christmas_Eve = cf.get("configuration", "str_Christmas_Eve")
str_Christmas = cf.get("configuration", "str_Christmas")
str_birthday = cf.get("configuration", "str_birthday")

Bot Initialization

The script creates a Bot instance differently for Windows/macOS and Linux to handle QR‑code login.

if 'Windows' in platform.system():
    bot = Bot()
elif 'Darwin' in platform.system():
    bot = Bot()
elif 'Linux' in platform.system():
    bot = Bot(console_qr=2, cache_path=True)
else:
    print("Unable to detect OS, please set manually")

English Learning

Daily English sentences are fetched from the free API http://open.iciba.com/dsapi/.

def get_message():
    r = requests.get("http://open.iciba.com/dsapi/")
    note = r.json()['note']
    content = r.json()['content']
    return note, content

Sentiment Analysis

Incoming messages are sent to BosonNLP’s sentiment API; the returned score (0‑1) indicates mood.

postData = {'data': msg.text}
response = post('https://bosonnlp.com/analysis/sentiment?analysisType=', data=postData)
data = response.text
now_mod_rank = (data.split(',')[0]).replace('[[','')
print(f"Message: {msg.text}
Sentiment score: {now_mod_rank}")

Message Sending Function

def send_message(your_message):
    try:
        my_friend = bot.friends().search(my_lady_wechat_name)[0]
        my_friend.send(your_message)
    except:
        bot.file_helper.send(u"守护女友出问题了,赶紧去看看咋回事~")

Scheduling Loop

An infinite loop checks the current time string and triggers the appropriate greeting. Emoji addition and English learning flags are respected.

while True:
    now_time = time.ctime()[-13:-8]
    if now_time == say_good_morning:
        message = choice(str_list_good_morning)
        if flag_wx_emoj:
            message += choice(str_list_emoj)
        send_message(message)
    # similar blocks for lunch, dinner, sleep, birthday, holidays, etc.
    time.sleep(60)

Running the Bot

t = Thread(target=start_care, name='start_care')
t.start()

Installation

pip install wxpy

pip install requests

Source Code

Full source code is available at https://github.com/shengqiangzhang/examples-of-web-crawlers

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonAutomationSchedulingSentiment AnalysisWeChat botwxpy
dbaplus Community
Written by

dbaplus Community

Enterprise-level professional community for Database, BigData, and AIOps. Daily original articles, weekly online tech talks, monthly offline salons, and quarterly XCOPS&DAMS conferences—delivered by industry experts.

0 followers
Reader feedback

How this landed with the community

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.