diff --git a/core/command.py b/core/command.py index f79cc2f..a766f70 100644 --- a/core/command.py +++ b/core/command.py @@ -13,7 +13,7 @@ from lib import common import uuid from base64 import b64decode -from lib.common import WorkPlace +from lib.common import WorkPlace, College def _send_msg(local_func, remote_func, to, content, thread_type, suffix): @@ -164,8 +164,11 @@ class Executor(): return objects def addWork(self, work_detail, privacy='EVERYONE'): - print(work_detail) work = WorkPlace.from_dict(work_detail) - print(work) res = self.client.addWorkPlace(work, privacy) return res + + def addSchool(self, school_detail, privacy="EVERYONE"): + school = College.from_dict(school_detail) + res = self.client.addCollege(school, privacy) + return res diff --git a/lib/common.py b/lib/common.py index 0b9a7cf..5492629 100644 --- a/lib/common.py +++ b/lib/common.py @@ -105,6 +105,31 @@ class College(): return data + @classmethod + def from_dict(cls, data: dict): + self = cls() + for k, v in data.items(): + if hasattr(self, k): + setattr(self, k, v) + + start_time = [] + end_time = [] + for x in ['year', 'month', 'day']: + if data.get(f'date_start[{x}]'): + start_time.append(int(data.get(f'date_start[{x}]'))) + + if data.get(f'date_end[{x}]'): + end_time.append(int(data.get(f'date_end[{x}]'))) + if start_time: + self.start_time = datetime.date(*start_time) + + if end_time: + self.end_time = datetime.date(*end_time) + self.graduated = True + + return self + + class TaskStatus(): EXCEPTION = -2 FAILED = -1 diff --git a/lib/facebook.py b/lib/facebook.py index 9bed27a..e322f19 100644 --- a/lib/facebook.py +++ b/lib/facebook.py @@ -336,8 +336,10 @@ class FacebookClient(Client): 'error': res['jsmods']['require'] } - def addCollege(self, college: College): + def addCollege(self, college: College, value='EVERYONE'): '''添加教育记录''' + + value = PostParam.__dict__.get(value).value data = { 'experience_type': '2004', 'degree_id': '0', @@ -345,10 +347,19 @@ class FacebookClient(Client): 'ref': 'about_tab', 'action_type': 'add', 'experience_id': '0', - 'privacy[1588594478034907]': PostParam.EVERYONE.value} + 'privacy[1588594478034907]': value} data.update(college.to_dict()) res = self._post('/profile/edit/edu/save/', data) - return res + try: + return { + 'success': True, + 'setting': res['jsmods']['require'][1][3][0]['props'] + } + except: + return { + 'success': False, + 'error': res['jsmods']['require'] + } def setCurrentCity(self, city_id, city_name): '''