Python itchat.run() Examples
The following are 10
code examples of itchat.run().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
itchat
, or try the search function
.
Example #1
Source File: wechat.py From WerewolvesWechatBot with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: wechat.py From fishroom with GNU General Public License v3.0 | 5 votes |
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, (), ) ])
Example #3
Source File: WeChatAssistant.py From WeChatAssistant with Apache License 2.0 | 5 votes |
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()
Example #4
Source File: autoReply.py From WechatHelper with MIT License | 5 votes |
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()
Example #5
Source File: antiWithdrawal.py From WechatHelper with MIT License | 5 votes |
def run(self): try: itchat.auto_login(hotReload=True) except: itchat.auto_login(hotReload=True, enableCmdQR=True) itchat.run()
Example #6
Source File: wechat.py From anack with GNU General Public License v3.0 | 5 votes |
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()
Example #7
Source File: main.py From EverydayWechat with MIT License | 5 votes |
def run(): """ 主运行入口 """ # 判断是否登录,如果没有登录则自动登录,返回 False 表示登录失败 print('开始登录...') if not is_online(auto_login=True): print('程序已退出...') return
Example #8
Source File: User.py From TouchFish with MIT License | 5 votes |
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') # 加载群聊
Example #9
Source File: __init__.py From TWchat with MIT License | 4 votes |
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()
Example #10
Source File: main.py From EverydayWechat with MIT License | 4 votes |
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