當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。