Esempio n. 1
0
def download_files(msg):
    '''下载一些文件'''
    group_dict = Group.name_id_dict()

    group = msg.User.NickName
    group_id = group_dict.get(group, 'group_name')
    data = {
        'id': msg.NewMsgId,
        'type': msg.Type,
        'create_time': float(msg.CreateTime),
        'group': group,
        'group_id': group_id,
        'user_actual_name': msg.ActualNickName,
    }
    file_type = msg.type
    file_path = os.path.join(basedir, 'data', group, file_type)
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    fileName = os.path.join(file_path, msg.fileName)
    msg.download(fileName)
    data['content'] = fileName
    group_msg = GroupMsg.create(data)

    msg['Text'] = '下载方法'
    log(zh_str(msg), 'file.txt')
    log(zh_str(group_msg.to_dict()), 'down_load.txt')
    print '@%s@%s' % (msg.type, msg.fileName)
Esempio n. 2
0
 def text_reply(msg):
     '''保存文字类信息'''
     log(zh_str(msg))
     group = msg.User.NickName
     data = {
         'id': msg.NewMsgId,
         'type': msg.Type,
         'create_time': float(msg.CreateTime),
         'group': group,
         'group_id': "group_name",
         'user_actual_name': msg.ActualNickName,
         'content': msg.Text,
     }
     group_msg = GroupMsg.create(data)
     log(zh_str(group_msg.to_dict()), 'text.txt')
     print '%s: %s' % (msg.type, msg.text)
Esempio n. 3
0
def text_reply(msg):
    '''保存分享类信息'''
    group_dict = Group.name_id_dict()
    group = msg.User.NickName
    group_id = group_dict.get(group, 'group_name')
    data = {
        'id': msg.NewMsgId,
        'type': msg.Type,
        'create_time': float(msg.CreateTime),
        'group': group,
        'group_id': group_id,
        'user_actual_name': msg.ActualNickName,
        'content': msg.Text,
    }
    group_msg = GroupMsg.create(data)
    sharing_msg = Sharing.create(msg)
    # log(zh_str(msg))
    log(zh_str(group_msg.to_dict()), 'text.txt')
    log(zh_str(sharing_msg.to_dict()), 'sharing.txt')
    print '%s: %s' % (msg.type, msg.text)
Esempio n. 4
0
def text_reply(msg):
    '''保存分名片类信息'''
    log(zh_str(msg))
    group_dict = Group.name_id_dict()

    group = msg.User.NickName
    group_id = group_dict.get(group, 'group_name')
    data = {
        'id': msg.NewMsgId,
        'type': msg.Type,
        'create_time': float(msg.CreateTime),
        'group': group,
        'group_id': group_id,
        'user_actual_name': msg.ActualNickName,
        'content': msg.Text['NickName'],
    }

    card_data = msg.Text
    card_data['id'] = msg.NewMsgId
    card = Card.create(card_data)
    group_msg = GroupMsg.create(data)
    log(zh_str(card.to_dict()), 'card.txt')
    log(zh_str(group_msg.to_dict()), 'text.txt')
    print '%s: %s' % (msg.type, msg.text)
Esempio n. 5
0
def get_user_list(itchat, room_name):
    '''
    获取用户列表,如果是新用户,将其插入到user表中
    '''
    chat_room = get_room_from_name(itchat, room_name)
    log(zh_str(chat_room), 'room.txt')
    for user in chat_room['MemberList']:

        file_path = download_header_img(itchat, chat_room, user)
        data = {
            'Group': room_name,
            'NickName': user['NickName'],
            'DisplayName': user['DisplayName'],
            'RemarkName': user['RemarkName'],
            'Province': user['Province'],
            'City': user['City'],
            'Signature': user['Signature'],
            'Sex': user['Sex'],
            'HeadImgUrl': file_path,
            'GroupName': room_name + '$:$' + user['NickName']
        }
        u = User.create(data)
        log(zh_str(u.to_dict()), 'user.txt')
        log(zh_str(user), 'basic_user.txt')