Nanfeng

Notes on software development, code, and curious ideas

Sending a One-Time WeChat Reminder with Python

The original script sent a message forever every half-second. That behavior is spam, can harass the recipient, and may cause account restrictions. This safer adaptation sends exactly one message after explicit confirmation and is suitable only for a contact who has agreed to receive the automated reminder.

itchat depends on WeChat web-login behavior that may no longer be available for many accounts, and unofficial automation may conflict with platform terms. Prefer an official API for production use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import itchat

print("Scan the displayed QR code to sign in")
itchat.auto_login(hotReload=False)

remark_name = input("Contact remark name: ").strip()
message = input("One-time reminder text: ").strip()

matches = itchat.search_friends(remarkName=remark_name)
if not matches:
raise SystemExit("No matching contact was found")

confirmation = input(
f"Send this message once to {remark_name}? Type SEND to confirm: "
).strip()

if confirmation == "SEND":
itchat.send_msg(
msg=message,
toUserName=matches[0]["UserName"]
)
print("Message sent once")
else:
print("Cancelled")

Do not turn this into an infinite loop, use it for bulk messaging, evade rate limits, or message people without consent. Never automate sensitive content or credentials through an unofficial client.

+