当前位置: 首页>>代码示例>>Python>>正文


Python itchat.run方法代码示例

本文整理汇总了Python中itchat.run方法的典型用法代码示例。如果您正苦于以下问题:Python itchat.run方法的具体用法?Python itchat.run怎么用?Python itchat.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在itchat的用法示例。


在下文中一共展示了itchat.run方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def __init__(self, game_controller):
        super().__init__(game_controller)

        self.username_to_user = {} # Map Wechat user name to WechatUser object
        self.send_msg_queue = queue.Queue() # Avoid sending messages too fast by buffering

        # Start listening Wechat messages
        itchat.auto_login()
        threading.Thread(target = itchat.run).start()

        # Send messages in another thread
        threading.Thread(target = self.send_messages_in_queue).start()

        # Accept new messages from players
        @itchat.msg_register(itchat.content.TEXT)
        def listen_wechat_message(message_info):
            username = message_info['User']['UserName'] # User name of the Wechat user
            text = message_info['Text'] # Content of the message
            self.got_message(username, text) 
开发者ID:LouYu2015,项目名称:WerewolvesWechatBot,代码行数:21,代码来源:wechat.py

示例2: main

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def main():
    if "wechat" not in config:
        return

    from .runner import run_threads
    bot, im2fish_bus, fish2im_bus = init()
    wxdebug()
    # The two threads and itchat.run are all blocking,
    # so put all of them in run_threads
    run_threads([
        (Wechat2FishroomThread, (bot, im2fish_bus, ), ),
        (Fishroom2WechatThread, (bot, fish2im_bus, ), ),
        (itchat.run, (), )
    ]) 
开发者ID:tuna,项目名称:fishroom,代码行数:16,代码来源:wechat.py

示例3: wechat_login

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def wechat_login(self):
        try:
            itchat.auto_login(hotReload=True)
        except:
            q.put("您的微信未能正确登陆,可能是注册时间太短,微信禁止登陆网页版微信")
        chatroomsList =itchat.get_chatrooms()
        for chatroom in chatroomsList:
            group_list.append(chatroom["NickName"])
        js.writejson('groupdata.json',group_list)
        self.ShowGroup()
        self.ShowFriends()
        itchat.run() 
开发者ID:LyuDun,项目名称:WeChatAssistant,代码行数:14,代码来源:WeChatAssistant.py

示例4: run

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def run(self, keywords=None, replycontents=None):
		if keywords is not None:
			global KEYWORDS
			KEYWORDS = keywords
		if replycontents is not None:
			global RELAYCONTENTS
			RELAYCONTENTS = replycontents
		try:
			itchat.auto_login(hotReload=True)
		except:
			itchat.auto_login(hotReload=True, enableCmdQR=True)
		itchat.run() 
开发者ID:CharlesPikachu,项目名称:WechatHelper,代码行数:14,代码来源:autoReply.py

示例5: run

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def run(self):
		try:
			itchat.auto_login(hotReload=True)
		except:
			itchat.auto_login(hotReload=True, enableCmdQR=True)
		itchat.run() 
开发者ID:CharlesPikachu,项目名称:WechatHelper,代码行数:8,代码来源:antiWithdrawal.py

示例6: text_reply

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def text_reply(msg):
#    msg.user.send('%s: %s' % (msg.type, msg.text))  #终于发出消息了
    who = msg['ActualNickName']    #获取发送人的名称
    content = msg['Text']
    print(who,'call me')
    if content == 'logout' or content == 'quit' or content == 'exit':
        itchat.logout()
        return
    ### 发送内容有三种方式:给自己、给别人、给群聊(示例程序),测试成功
#    if who == '尹超': 
#        SendText2Friend('yc send')    #给自己(文件助手)
#        SendTxet2ChatRoom('yc send','啊啊啊') #给指定群聊
#    else:
#        SendText2Friend('ali send','阿狸')   #给指定的人
#        SendTxet2ChatRoom('ali send','啊啊啊') #给指定群聊
        
    #-------------------------------------------------
    authority = ['尹超','徐抒田','李航','李繁','鹏','顾秋杨']
#    if who in authority: #此处有bug,自己先发送的话who为空,必须别人先发信息
    if 1:
#        print(content)
        result = ATDecoder(content)
#        print(result)
        if result != None:
            SendText2ChatRoom(result,'啊啊啊') #给指定群聊
#    else:
#        print('no reply')
    #-------------------------------------------------------------------    
    time.sleep(1)
########################################################################
#WechatLogin()
#SendText2Friend('test')
#SendText2Friend('test','阿狸')
#SendTxet2ChatRoom('test','啊啊啊')
#itchat.run() 
开发者ID:YinChao126,项目名称:anack,代码行数:37,代码来源:wechat.py

示例7: run

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def run():
    """ 主运行入口 """
    # 判断是否登录,如果没有登录则自动登录,返回 False 表示登录失败
    print('开始登录...')
    if not is_online(auto_login=True):
        print('程序已退出...')
        return 
开发者ID:sfyc23,项目名称:EverydayWechat,代码行数:9,代码来源:main.py

示例8: __init__

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def __init__(self):
        self.user_count = 0
        self.selfUser = None
        self.user_dict = {}
        self.current_user = None    # 当前正在聊天的用户
        self.room_dept = -1          # 用于记录好友和群聊的分界点id
        self.cmd = Cmd(self)        # 初始化一个命令管理器, 此命令管理器管理所有的命令

        itchat.auto_login(hotReload=True,enableCmdQR = 2,exitCallback=itchat.logout) #登录并记录登录状态
        threading.Thread(target=itchat.run).start()             # 线程启动run实现
        self.loadUserList(itchat.get_friends(),'f')             # 加载好友
        self.loadUserList(itchat.get_chatrooms(),'r')           # 加载群聊 
开发者ID:TheThreeDog,项目名称:TouchFish,代码行数:14,代码来源:User.py

示例9: start

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def start():
    @itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING,PICTURE, RECORDING, ATTACHMENT, VIDEO,FRIENDS])
    def recive_contact_msg(msg):
        contact_name = get_contact_name(msg)
        try:
            wechatMain.recive_message(msg,contact_name)
            notify('TWchat',"new message from: "+contact_name)
        except AttributeError:
            pass
    
    @itchat.msg_register(TEXT, isGroupChat=True)
    def recive_group_msg(msg):
        group_name = get_group_name(msg)
        try:
            wechatMain.recive_message(msg,group_name)
            notify('TWchat',"new message from: "+group_name)
        except AttributeError:
            pass
        return   

    def on_contact_item_click(button,info):
        wechatMain.chatListBox.addNewChat(info[0],info[1])
        wechatMain.set_current_chat(info[0],info[1])
        wechatMain.chatListBox.show_chat()
        return 
    def on_chat_item_click(button,info):
        wechatMain.set_current_chat(info[0],info[1])
        return
    palette = [
        ('left', 'black', 'light gray'),
        ('right', 'black', 'dark cyan'),
        ('button', 'dark green','black'),
        ('mybg', 'black','dark cyan'),
        ('tobg', 'dark blue','light gray'),
        ('edit', 'dark cyan','black'),
        ('bg', 'dark green', 'black'),]
    print ('''
 _____  _    _  _____  _   _   ___   _____ 
|_   _|| |  | |/  __ \| | | | / _ \ |_   _|
  | |  | |  | || /  \/| |_| |/ /_\ \  | |  
  | |  | |/\| || |    |  _  ||  _  |  | |  
  | |  \  /\  /| \__/\| | | || | | |  | |  
  \_/   \/  \/  \____/\_| |_/\_| |_/  \_/  
            ''')

    wechatMain = wegui.WechatMain(palette)
    itchat.auto_login(enableCmdQR=2,hotReload=True)
    itchat.run(blockThread=False)
    userInfo =itchat.web_init()['User']
    owner_id = userInfo['UserName']
    owner_name = userInfo['NickName']
    contactlist= itchat.get_friends(update=True)
    chatlist = itchat.get_chatrooms()
    #contactlist = sorted(contactlist,key=lambda x:(x['RemarkPYInitial'],x['PYInitial']))
    contactlist = sorted(contactlist,key=lambda x:(lazy_pinyin(get_name(x))))
    wechatMain.initUserInfo(owner_id,owner_name,on_contact_item_click,on_chat_item_click,contactlist,chatlist)
    wechatMain.bind_itchat(itchat)
    wechatMain.createLoop() 
开发者ID:huanglizhuo,项目名称:TWchat,代码行数:60,代码来源:__init__.py

示例10: is_online

# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import run [as 别名]
def is_online(auto_login=False):
    """
    判断是否还在线。
    :param auto_login: bool,当为 Ture 则自动重连(默认为 False)。
    :return: bool,当返回为 True 时,在线;False 已断开连接。
    """

    def _online():
        """
        通过获取好友信息,判断用户是否还在线。
        :return: bool,当返回为 True 时,在线;False 已断开连接。
        """
        try:
            if itchat.search_friends():
                return True
        except IndexError:
            return False
        return True

    if _online(): return True  # 如果在线,则直接返回 True
    if not auto_login:  # 不自动登录,则直接返回 False
        print('微信已离线..')
        return False

    # hotReload = not config.get('is_forced_switch', False)  # 切换微信号,重新扫码。
    hotReload = False  # 2019年9月27日15:31:22 最近保存最近登录状态出错,所以先设置每次都得扫码登录
    loginCallback = init_data
    exitCallback = exit_msg
    try:
        for _ in range(2):  # 尝试登录 2 次。
            if platform.system() in ('Windows', 'Darwin'):
                itchat.auto_login(hotReload=hotReload,
                                  loginCallback=loginCallback, exitCallback=exitCallback)
                itchat.run(blockThread=True)
            else:
                # 命令行显示登录二维码。
                itchat.auto_login(enableCmdQR=2, hotReload=hotReload, loginCallback=loginCallback,
                                  exitCallback=exitCallback)
                itchat.run(blockThread=True)
            if _online():
                print('登录成功')
                return True
    except Exception as exception:  # 登录失败的错误处理。
        sex = str(exception)
        if sex == "'User'":
            print('此微信号不能登录网页版微信,不能运行此项目。没有任何其它解决办法!可以换个号再试试。')
        else:
            print(sex)

    delete_cache()  # 清理缓存数据
    print('登录失败。')
    return False 
开发者ID:sfyc23,项目名称:EverydayWechat,代码行数:54,代码来源:main.py


注:本文中的itchat.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。