From 1b51b3ae3bf5be65318e52b6ba7d96be3bb5434f Mon Sep 17 00:00:00 2001 From: chenjunxue <1523825571@qq.com> Date: Tue, 8 Sep 2020 18:36:00 +0800 Subject: [PATCH] 2.3.8 增加新版本分组接口,增加可以检索公开,非公开,我的分组,按照城市过滤 增加分组过滤城市检索功能 --- conf/config.yaml | 4 ++-- core/callback.py | 5 ++++- lib/facebook.py | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/state.py | 2 +- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 65d76c0..8e895ce 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -4,5 +4,5 @@ SERVER: reconnect_interval: 3 VERSION: - code: 127 - name: 2.3.7 \ No newline at end of file + code: 128 + name: 2.3.8 \ No newline at end of file diff --git a/core/callback.py b/core/callback.py index d5f6180..bc2c46f 100644 --- a/core/callback.py +++ b/core/callback.py @@ -57,7 +57,10 @@ class CallBack(): def onLoggingIn(self, email, password, cookie, user_agent=None, proxy=None, clear: bool = False): if clear: print('清理缓存登录', email) - models.UserList.remove(email=email) + try: + models.UserList.remove(email=email) + except: + pass user_obj = models.UserList.get(email=email) if not user_obj: print('初次登录') diff --git a/lib/facebook.py b/lib/facebook.py index 41fecf0..4e6edaa 100644 --- a/lib/facebook.py +++ b/lib/facebook.py @@ -886,6 +886,8 @@ class FacebookClient(Client): if not ext_data: from urllib import parse filter = 'eyJncm91cHNfc2hvd19vbmx5Ijoie1wibmFtZVwiOlwicHVibGljX2dyb3Vwc1wiLFwiYXJnc1wiOlwiXCJ9In0%3D' + # filter = 'eyJwdWJsaWNfZ3JvdXBzIjoie1wibmFtZVwiOlwicHVibGljX2dyb3Vwc1wiLFwiYXJnc1wiOlwiXCJ9In0%3D' + # https://www.facebook.com/search/groups?q=%E5%91%A8%E6%9D%B0%E4%BC%A6&filters=eyJwdWJsaWNfZ3JvdXBzIjoie1wibmFtZVwiOlwicHVibGljX2dyb3Vwc1wiLFwiYXJnc1wiOlwiXCJ9In0%3D r = self._state._session.get( f'https://www.facebook.com/search/groups/?q={parse.quote(name)}&epa=FILTERS&filters={filter}') fbid = parse_html.get_all_group(r.text) @@ -904,6 +906,46 @@ class FacebookClient(Client): 'ext_data': ext_data, } + def SearchRenderable(self, name, cursor='', filters=[]): + """新搜索群组功能""" + if not cursor: + cursor = None + variables = { + "allow_streaming": False, + "args": { + "callsite": "COMET_GLOBAL_SEARCH", + "config": {"bootstrap_config": None, "exact_match": False, "high_confidence_config": None, + "watch_config": None}, + "context": {"bsid": "b3e300c-1a0b-4643-91a7-d34a582fbb6b", "tsid": "0.4453413139497706"}, + "experience": {"fbid": None, "grammar_bqf": None, "role": None, "type": "GROUPS_TAB"}, + "filters": filters, + "text": name}, "cursor": cursor, "feedbackSource": 23, + "fetch_filters": True, "scale": 2, "stream_initial_count": 0} + try: + res = self.graphql_api('CometSearchResultsInitialResultsQuery', '4370093036395458', variables) + if 'errors' in res: + return {'success': False, 'errors': res['errors']} + else: + return {'success': True, 'data': res['data']} + except Exception as e: + return {'success': False, 'errors': str(e)} + + def GraphSearchQueryFilter(self, city): + """搜索分组过滤地区""" + variables = {"count": 8, + "filterID": "Z3NxZjp7IjAiOiJicm93c2VfaW5zdGFudF9maWx0ZXIiLCIxIjoia2V5d29yZHNfZ3JvdXBzKFx1MDAyNUU1XHUwMDI1OTFcdTAwMjVBOFx1MDAyNUU2XHUwMDI1OURcdTAwMjVCMFx1MDAyNUU0XHUwMDI1QkNcdTAwMjVBNikiLCIzIjoiNDRiYzM4MTYtOWQwNS00NWQyLTljMDAtN2M0MzMyMGQwMzM1IiwiY3VzdG9tX3ZhbHVlIjoiQnJvd3NlR3JvdXBzQ2l0eUluc3RhbnRGaWx0ZXJDdXN0b21WYWx1ZSJ9", + "profile_picture_size": None, "query": city} + try: + res = self.graphql_api('useCometSearchFilterTypeaheadCompositeNetworkDataSourceQuery', '2065678270223319', + variables) + if 'errors' in res: + return {'success': False, 'errors': res['errors']} + else: + return {'success': True, 'data': res['data']} + except Exception as e: + return {'success': False, 'errors': str(e)} + pass + def searchForPostByPublic(self, keyword, ext_data=None): if not ext_data: f = furl.furl('https://www.facebook.com/search/posts/') diff --git a/lib/state.py b/lib/state.py index 68b923d..0bd5d79 100644 --- a/lib/state.py +++ b/lib/state.py @@ -166,7 +166,7 @@ class PCState(State): 'lgnjs': int(time.time()), 'timezone': '-480' }) - r = session.post('https://zh-cn.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110', + r = session.post('https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110', data=data) setCookie = r.headers.get('Set-Cookie') or '' -- libgit2 0.24.0