本文整理匯總了Python中itchat.get_chatrooms方法的典型用法代碼示例。如果您正苦於以下問題:Python itchat.get_chatrooms方法的具體用法?Python itchat.get_chatrooms怎麽用?Python itchat.get_chatrooms使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類itchat
的用法示例。
在下文中一共展示了itchat.get_chatrooms方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SendText2ChatRoom
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def SendText2ChatRoom(context, name):
'''
@ 發送消息到特定群聊內
@ 備注:1.確定該群聊存在(可調用PrintChatRoomList查看)
@ 2.切記把群聊加入通訊錄,否則隻能顯示活躍的前幾個群聊
'''
itchat.get_chatrooms(update=True)
iRoom = itchat.search_chatrooms(name)
for room in iRoom:
if room['NickName'] == name:
userName = room['UserName']
break
try:
itchat.send_msg(context, userName)
except:
print('warning: no this chatrooms')
示例2: __init__
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def __init__(self, roomNicks):
global wxRooms, myUid
itchat.auto_login(hotReload=True, enableCmdQR=2, exitCallback=wechatExit)
all_rooms = itchat.get_chatrooms(update=True)
for r in all_rooms:
if r['NickName'] in roomNicks:
wxRooms[r['UserName']] = r['NickName']
wxRoomNicks[r['NickName']] = r['UserName']
logger.info('Room {} found.'.format(r["NickName"]))
else:
logger.info('{}: {}'.format(r['UserName'], r['NickName']))
friends = itchat.get_friends()
myUid = friends[0]["UserName"]
示例3: send_to_group_chat
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def send_to_group_chat(target_group_chat_name, file_names):
"""
群聊
:param target_group_chat_name:
:param file_name:
:return:
"""
rooms = itchat.get_chatrooms(update=True)
# 目標群聊對象
target_room = None
for room in rooms:
group_chat_name = room.get('NickName')
if target_group_chat_name == group_chat_name:
target_room = room
break
if target_room:
if isinstance(file_names, list):
for file_name in file_names:
target_room.send_image(file_name)
else:
target_room.send_image(file_names)
print('發送完畢!')
else:
print('抱歉,不存在這個群聊')
示例4: wechat_login
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [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()
示例5: PrintChatRoomList
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def PrintChatRoomList():
'''
@ 顯示當前可見的群聊名
'''
rooms = itchat.get_chatrooms(update=True)
for s in rooms:
print(s['NickName'])
示例6: init_data
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def init_data():
""" 初始化微信所需數據 """
set_system_notice('登錄成功')
itchat.get_friends(update=True) # 更新好友數據。
itchat.get_chatrooms(update=True) # 更新群聊數據。
init_wechat_config() # 初始化所有配置內容
# 提醒內容不為空時,啟動定時任務
alarm_dict = config.get('alarm_info').get('alarm_dict')
if alarm_dict:
init_alarm(alarm_dict) # 初始化定時任務
print('初始化完成,開始正常工作。')
示例7: get_group
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def get_group(group_name, update=False):
"""
根據群組名獲取群組數據
:param group_name:str, 群組名
:param update: bool 強製更新群組數據
:return: obj 單個群組信息
"""
if update: itchat.get_chatrooms(update=True)
if not group_name: return None
groups = itchat.search_chatrooms(name=group_name)
if not groups: return None
return groups[0]
示例8: __init__
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [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') # 加載群聊
示例9: reloadUserList
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [as 別名]
def reloadUserList(self):
'''
重載好友列表,如果程序運行期間添加了好友或群聊,通過此命令刷新
'''
self.selfUser = None
self.current_user = None
self.user_dict = {}
self.user_count = 0
self.loadUserList(itchat.get_friends(),'f') # 加載好友
self.loadUserList(itchat.get_chatrooms(),'r') # 加載群聊
示例10: start
# 需要導入模塊: import itchat [as 別名]
# 或者: from itchat import get_chatrooms [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()