用python接入微信聊天機械人

2021-08-17 14:11:03 字數 1154 閱讀 2770

pip install -u wxpy
pip install -u wxpy -i

""

from wxpy import *

bot = bot(cache_path=true) #掃碼登入驗證

friends_stat = bot.friends().stats()

friend_loc = # 每乙個元素是乙個二元列表,分別儲存地區和人數資訊

for province, count in friends_stat["province"].items():

if province != "":

# 對好友人數倒序排序

friend_loc.sort(key=lambda x: x[1], reverse=true)

# 列印好友人數最多的10個地區:

for item in friend_loc[:10]:

print(item[0], item[1])

#列印好友男女比例:

for ***, count in friends_stat["***"].items():

# 1代表male, 2代表female

if *** == 1:

print("male %d" % count)

elif *** == 2:

print("female %d" % count)

from wxpy import *

bot = bot(cache_path=true)

my_friend = bot.friends().search('好友暱稱')[0] #定位好友

my_friend.send('hello!') #傳送「hello!」測試一下對接是否成功。

group = bot.groups().search('群名')[0] #定位群

tuling = tuling(api_key='在申請')

# 使用圖靈機械人自動與指定好友聊天

@bot.register(my_friend)

defreply_my_friend

(msg):

tuling.do_reply(msg)

[1]

微信聊天機械人

import arrow import itchat import pydash import requests deflocal datetime 格式化的時間戳 return arrow.now format yyyy mm dd hh mm ss defget user info wx msg...

微信聊天機械人2019

新建乙個名為wechatrobot.py的檔案,內容如下 import urllib.parse import urllib.request from os import remove import itchat import requests from aip import aipimagecla...

微信自動聊天機械人

背景 操作步驟 操作過程 import requests import itchat 圖靈機人人的apikey key d7b92b1df4ef4ba6a6c649200208f103 defget response msg 這個位址在此處給出,一看就懂 apiurl data的本質是乙個地點,要想...