Esempio n. 1
0
    def do_init_env(self):
        print("[{}]Initializing it chat ...".format(
            time.strftime("%H:%M:%S", time.localtime())))
        time.sleep(5)
        # init chat room
        chatrooms = self.chat_it.get_chatrooms()
        for chatroom in chatrooms:
            # print("Chatroom userName: {}".format(chatroom.userName))
            if chatroom.nickName == GROUP_NAME:
                # print("chatroom nickName: {} is my room".format(chatroom.nickName))
                self.room_name = chatroom.userName
                self.room_nick = chatroom.nickName
            else:
                # print("chatroom nickName: {} is not my room".format(chatroom.nickName))
                pass
        # init contacts
        chat_room = self.chat_it.update_chatroom(self.room_name,
                                                 detailedMember=True)
        for friend in chat_room['MemberList']:
            c = self.chat_it.search_friends(userName=friend['UserName'])
            # print("UserName: {}".format(c['UserName']))
            # print("DisplayName: {}".format(c['DisplayName']))
            # print("RemarkName: {}".format(c['RemarkName']))
            # print("NickName: {}".format(c['NickName']))
            contact = Contact()
            contact.id = 0
            contact.achat_name = ACHAT_NAME
            contact.uin = c.Uin
            contact.user_name = c.UserName
            contact.nick_name = c.NickName
            contact.remark_name = c.RemarkName
            contact.flag = c.ContactFlag
            contact.member_count = c.MemberCount
            contact.sex = c.Sex
            contact.signature = c.Signature
            contact.isowner = 0

            last_id = self.chat_db.save_new_contact(contact)
            print("Contact ID inserted is " + str(last_id))
        #
        print("Initializing it chat completed.")
        pass