python中itchat_python打招呼的代码
				python,itchat,打招呼,代码 
                                
                    2025-03-13 21:27:28 时间  
                                                大家好,又见面了,我是你们的朋友全栈君。
#!/usr/bin/envy python3
#-*- coding:utf-8 -*-
import itchat
import datetime, os, platform,time
def timerfun(sched_time) :
    flag = 0
    while True:
        now = datetime.datetime.now()
        if now > sched_time and now < sched_time + datetime.timedelta(seconds=1) :  # 因为时间秒之后的小数部分不一定相等,要标记一个范围判断
            send_move()
            time.sleep(1)    # 每次判断间隔1s,避免多次触发事件
            flag = 1
        else :
            #print('schedual time is {0}'.format(sched_time))
            #print('now is {0}'.format(now))
            if flag == 1 :
                sched_time = sched_time + datetime.timedelta(hours=1)  # 把目标时间增加一个小时,一个小时后触发再次执行
                flag = 0
def send_move :
    # nickname = input('please input your firends\' nickname : ' )
    #   想给谁发信息,先查找到这个朋友,name后填微信备注即可,deepin测试成功
    # users = itchat.search_friends(name=nickname)
    users = itchat.search_friends(name='大壮')   # 使用备注名来查找实际用户名
    #获取好友全部信息,返回一个列表,列表内是一个字典
    print(users)
    #获取`UserName`,用于发送消息
    userName = users[0]['UserName']
    itchat.send("该起来动一下了!",toUserName = userName)
    print('succeed')
if __name__=='__main__':
    itchat.auto_login(hotReload=True)  # 首次扫描登录后后续自动登录
    sched_time = datetime.datetime(2018,7,12,13,24,11)   #设定初次触发事件的事件点
    print('run the timer task at {0}'.format(sched_time))
    timerfun(sched_time)需要注意的是需要先下载itchat,方法为pip install itchat ,python3.6自带pip, 只需在scripts目录下按住shift鼠标点击右键即可,运行命令即可
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/188582.html原文链接:https://javaforall.cn
相关文章
- Python-基础06-文件操作
 - pycharm搭建python环境_pycharm如何配置编译环境
 - pycharm 删除项目_pycharm怎么删除python文件
 - Python基础17-面向对象
 - python类的初始化方法_python初始化列表
 - python计算双色球数字概率_python绘制双色球走势图
 - pycharm安装opencv-python_geany配置python
 - linux golang环境安装_python环境搭建
 - Python DB-API 规范及 MySQL Connector/Python 实现
 - Python继续霸榜,SQL写得溜,面试或许能加分
 - pycharm中pyqt5使用方法_python环境变量的配置
 - python写入txt文件中文乱码_python中怎么输入文件
 - termux更改镜像源_pycharm自带python
 - python ssh连接_pycharm显示no module named
 - linux安装python虚拟环境_windows安装python虚拟环境
 - pycharm配置Python环境_手机虚拟环境怎么设置
 - Python元祖详解
 - python虚拟环境virtualenv_怎样用pycharm写代码
 - pycharm如何安装第三方库_python第三方库离线安装
 - Python嵌套函数与匿名函数