def _get_contact(self, contact_data: json) -> iter: contact_all = contact_data.get('linkmanList') gname_map: dict = contact_data.get('uuidGuuidGnameMap') if contact_all is None or len(contact_all) == 0: self._logger.error("No contact in this account.") return for line_one in contact_all: contact_id = line_one.get('uuid') data_one = CONTACT_ONE(self._userid, contact_id, self.task, self.task.apptype) data_one.phone = line_one.get('mobile') data_one.email = line_one.get('email') data_one.nickname = line_one.get('name') data_one.group = gname_map[contact_id][0][0]['groupName'] yield data_one
def _get_contacts(self) -> iter: if self.sid is None: self._logger.error("Invalid cookie") url = "https://mail.yeah.net/contacts/call.do" querystring = { "uid": self._userid, "sid": self.sid, "from": "webmail", "cmd": "newapi.getContacts", "vcardver": "3.0", "ctype": "all", "attachinfos": "yellowpage,frequentContacts", "freContLim": "20" } payload = '''order=[{"field":"N","desc":"false"}]''' headers = f''' Accept: */* Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9,en;q=0.8 Cache-Control: no-cache Connection: keep-alive Content-Length: 36 Content-type: application/x-www-form-urlencoded Host: mail.163.com Origin: https://mail.yeah.net Pragma: no-cache Referer: https://mail.yeah.net/js6/main.jsp?sid={self.sid}&df=mail163_letter User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36 ''' try: # response = requests.request("POST", url, data=payload, headers=headers, params=querystring) res_test = self._ha.getstring(url, req_data=payload, headers=headers, params=querystring) res_text_json = json.loads(res_test) if res_text_json.get('code') != 200: self._logger.error( f"Get contacts error, err:{traceback.format_exc()}") return con_list = res_text_json.get('data').get('contacts') if con_list is None or len(con_list) == 0: return groups_dict = {} groups = res_text_json.get('data').get('groups') for group in groups: group_cid = group['CID'] group_name = group['N'] groups_dict[group_cid] = group_name con_all = CONTACT(self._clientid, self.task, self.task.apptype) for one in con_list: name = one.get('FN') mail = one.get('EMAIL;type=INTERNET;type=pref') con_one = CONTACT_ONE(self._userid, mail, self.task, self.task.apptype) con_one.email = mail con_one.nickname = name if 'GROUPING' in one: # 一个人可能有多个分组,用空格隔开 groupings = one.get('GROUPING').split(';') for i in range(len(groupings)): groupings[i] = groups_dict[groupings[i]] group_names = ' '.join(groupings) con_one.group = '=?utf-8?b?' + str( base64.b64encode(group_names.encode('utf-8')), 'utf-8') con_all.append_innerdata(con_one) if con_all.innerdata_len > 0: yield con_all except Exception: self._logger.error( f"Get contact error, err:{traceback.format_exc()}")