3 Star 16 Fork 13

kolly/wx-robot-demo

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
main.py 1.72 KB
Copy Edit Raw Blame History
kolly.li authored 2021-02-03 22:54 . init
# 导入模块
from wxpy import *
from common import web_spider
from jobs import *
logger = logging.getLogger('wx')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('wx-robot.log') # 输出日志到文件
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
sh = logging.StreamHandler() # 输出日志到终端
sh.setLevel(logging.DEBUG)
sh.setFormatter(formatter)
logger.addHandler(sh)
# 初始化机器人,扫码登陆
# bot = Bot(cache_path=True, qr_path="./qrcode.jpg")
bot = Bot(cache_path=True, console_qr=2)
# 启用 puid 属性,并指定 puid 所需的映射数据保存/载入路径
bot.enable_puid('wxpy_puid.pkl')
# 注册好友请求类消息
@bot.register(msg_types=FRIENDS)
def auto_accept_friends(msg):
# 自动接受好友请求
new_friend = msg.card.accept()
# 向新的好友发送消息
new_friend.send('哈喽~ 我是一个微信机器人 😆')
# 自动回复
@bot.register(chats=User)
def auto_reply(msg):
logger.info('收到好友「{}」消息:{}'.format(msg.sender.name, msg.text))
if '天气' == msg.text:
return web_spider.get_weather_today("shenzhen")
elif '我的基金' == msg.text:
return web_spider.get_zs_today() + '\n' + web_spider.get_jj_today("501301,161721")
else:
return ""
logger.info('====== 微信机器人已启动 ======')
# 启动定时任务
init_scheduler(bot)
# 打印信息
logger.info(bot)
logger.info(bot.friends())
logger.info(bot.registered)
# 进入 Python 命令行、让程序保持运行
bot.join()
# 程序退出时,发送企业微信消息
logger.info('====== 微信机器人已退出! ======')
sys.exit()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zgnbzgnb/wx-robot-demo.git
git@gitee.com:zgnbzgnb/wx-robot-demo.git
zgnbzgnb
wx-robot-demo
wx-robot-demo
master

Search