def msg():
     itchat.auto_login(True)
     #        time.sleep(10)
     global wcr_rep_flag, wcr_rep_Content
     while True:
         wcr_rep_Content = itchat.get_msg()
         if wcr_rep_Content[0] != None:
             if not len(wcr_rep_Content[0]) == 0:
                 wcr_rep_Content = wcr_rep_Content[0][0]['Content']
                 wcr_rep_flag = True
         time.sleep(.05)
Beispiel #2
0
def get_friends_info():
    try:
        itchat.auto_login(hotReload=True)
    except:
        itchat.auto_login(hotReload=True, enableCmdQR=True)
    friends_info = itchat.get_friends()
    mps_info = itchat.get_mps()  # 公众号信息
    chartrooms_info = itchat.get_chatrooms()  # 群信息
    head_img_info = itchat.get_head_img()  # 头像信息
    msg_info = itchat.get_msg()
    contact_info = itchat.get_contact()
    for info in chartrooms_info:
        print(info)
    with open('test.jpg', 'wb') as img:
        img.write(head_img_info)
        img.flush()
        img.close()
    with open('wechat_info.txt', 'w', encoding='utf-8') as file:
        for friend in friends_info:
            file.write(str(friend))
            file.write('\n\n\n')
 def run(self):
     autoreply = False
     while True:
         try:
             # 获取信息
             msgs = wc.get_msg()
             if msgs:
                 # 按次序提取信息
                 for msg in msgs[0]:
                     time.sleep(0.2)
                     try:
                         # 找到自己的发言,‘开始你的表演’,‘停止你的表演’ 作为开始和结束的指令
                         if msg['MsgType'] == 1:
                             if msg['FromUserName'] == wc.originInstance.storageClass.userName:
                                 if '开始你的表演' in msg['Content']:
                                     autoreply = True
                                     logging.info('表演开始咯')
                                     wc.send_msg('表演开始', self.xb)
                                 if '停止你的表演' in msg['Content']:
                                     autoreply = False
                                     logging.info('表演谢幕了')
                                     wc.send_msg('表演谢幕', self.xb)
                             elif '@@' not in msg['FromUserName'] and '@' in msg['FromUserName'] :
                                 # 获取不是小冰的信息
                                 if autoreply:
                                     if msg['FromUserName'] != self.xb:
                                         # 添加到接收列表
                                         self.mi.append(copy.deepcopy(msg))
                                     # 小冰的信息
                                     else:
                                         # 添加到回复列表
                                         self.mo.append(copy.deepcopy(msg))
                     except IndexError:
                         pass
         except:
             logging.warning('Getting module face a problem')
             pass
Beispiel #4
0
# coding=utf8
import itchat, time

itchat.auto_login(True)

SINCERE_WISH = u'祝%s新年快乐!'
a = itchat.get_friends(update=True)
itchat.get_chatrooms(update=True)
itchat.get_contact(update=True)

itchat.get_mps(update=True)
itchat.get_msg()

friendList = itchat.get_friends(update=True)[1:]
for friend in friendList:
    # 如果是演示目的,把下面的方法改为print即可
    # itchat.send(SINCERE_WISH % (friend['DisplayName']
    #                             or friend['NickName']), friend['UserName'])
    print("%s , %s" %
          (friend['DisplayName'] or friend['NickName'], friend['UserName']))
    # time.sleep(.5)
Beispiel #5
0
def simple_reply(msg):

    # 接收用户发送的消息
    message = msg['Content']

    print(message)

    # 判断发送内容格式是否合法并回复消息 '1#关键词'
    reply_message = ''

    #包含 # 号才回复消息:
    if '#' in message:

        #指令有误则提示出错
        if not message.split('#')[0].isdigit() or message.split('#')[1] == '':

            reply_message = '[Moue]亲,当前发送指令有误,请检查后重新发送。'

            # 给用户发送确认消息
            itchat.send(reply_message, msg['FromUserName'])

        #指令无误则开始后续工作
        else:

            reply_message = '[Determined]亲,已收到你的查询请求,请稍候...'

            # 给用户发送确认消息
            itchat.send(reply_message, msg['FromUserName'])

            # 切分群号与搜索关键词
            number, keyword = message.split('#')

            if keyword != '':
                # with open('pid.txt') as f:
                # 	content = f.read()
                # pid = content.split('\n')[int(number)]
                # print(pid)
                # print('\n✈  %s 群的查询关键词:%s ' % (number,keyword))

                #获取搜索结果的宝贝ID
                itemids, idnumber = search.search(keyword)

                # get username and pid
                username, pid = chatroom.get_chatroom_name(number)
                # print(username)
                # print(pid)

                if itemids == None:
                    #搜索到的宝贝ID列表为空
                    reply_content = '[Whimper]抱歉,当前关键词查询结果为空,请尝试一下替换其他关键词,谢谢。'
                    itchat.send(reply_content, msg['FromUserName'])

                else:
                    #正常搜索到宝贝ID列表
                    if itemids:
                        for k, itemid in enumerate(itemids):
                            item_content = content.get_content(itemid,
                                                               pid)  #获取完整广告内容
                            applys.apply_rate(itemid)  #自动申请定向计划

                            if item_content:

                                try:
                                    # 发送主图
                                    pic = content.get_image(itemid)
                                    itchat.send('@img@%s' % pic, username)
                                    itchat.get_msg()
                                except Exception as e:
                                    print("flag_2")
                                    print(Exception, ":", e)
                                time.sleep(5)

                                try:
                                    # 发送广告文案
                                    itchat.send(item_content, username)
                                    itchat.get_msg()
                                except Exception as e:
                                    print("flag_3")
                                    print(Exception, ":", e)
                                time.sleep(5)

                                # 删除已下载的图片
                                os.remove(pic)

                                print('✔ 亲,已成功发送了 %d 条宝贝信息' % (k + 1))

                            else:
                                # continue # content is None,need to fix
                                error_message = '小贝出了点小问题,请电话联系管理员,马上为您修复。'
                                itchat.send(error_message, msg['FromUserName'])
                                sys.exit()

                    else:
                        print("flag_4")

                    print('\n')

                    global i
                    i = i + 1

                    print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))

                    print('\n█▇▆▅▄▃▂  From', number, '群, Keyword:', keyword,
                          'Totle times:  ', i, '  次查询请求。 ▂▃▄▅▆▇█\n')

                    # 给用户发送成功消息

                    success_message = '[Joyful]宝贝信息已发送到您的群,请查看。'

                    itchat.send(success_message, msg['FromUserName'])
import itchat

itchat.auto_login()

# 获取自己的用户信息,返回自己的属性字典
print(itchat.search_friends())
# 获取任何一项等于name键值的用户
req = itchat.search_friends(name='梅林花开')
print(req)

print(req[0]['User']['UserName'])
print(itchat.get_msg())

# itchat.send('Hello, filehelper', toUserName='******')
Beispiel #7
0
import itchat
import cv2

itchat.auto_login(hotReload = True)

cv2.namedWindow("preview")
while(True):
    
    raw_msg = itchat.get_msg()
    
    if(not (raw_msg == (None, None) or raw_msg == ([], []))):
        if(not raw_msg[0][0].get('FromUserName') == raw_msg[0][0].get('ToUserName')):
            print(raw_msg)
        '''
        try:
            msg_content = raw_msg[0][0].get('Content')
            msg_tousername = raw_msg[0][0].get('FromUserName')
            if(not msg_content == ""):
                print(msg_tousername)
                print()
                print(msg_content)
        except:
            print("looool")
        '''
        
    
    key = cv2.waitKey(20)
    if key == 27:
        break
cv2.destroyWindow("preview")