正在显示
4 个修改的文件
包含
24 行增加
和
3 行删除
| @@ -4,6 +4,7 @@ | @@ -4,6 +4,7 @@ | ||
| 4 | # @Author : Lemon | 4 | # @Author : Lemon |
| 5 | # @File : core.py | 5 | # @File : core.py |
| 6 | # @Software: PyCharm | 6 | # @Software: PyCharm |
| 7 | +import datetime | ||
| 7 | import functools | 8 | import functools |
| 8 | import json | 9 | import json |
| 9 | 10 | ||
| @@ -89,6 +90,7 @@ def run(): | @@ -89,6 +90,7 @@ def run(): | ||
| 89 | sched = TornadoScheduler() | 90 | sched = TornadoScheduler() |
| 90 | sched.add_job(monitor._socket.sendheartbeat, 'interval', seconds=25) | 91 | sched.add_job(monitor._socket.sendheartbeat, 'interval', seconds=25) |
| 91 | sched.add_job(monitor._socket.auto_move_server, 'interval', seconds=31) | 92 | sched.add_job(monitor._socket.auto_move_server, 'interval', seconds=31) |
| 93 | + sched.add_job(monitor.go_login, next_run_time=datetime.datetime.now() + datetime.timedelta(seconds=5)) | ||
| 92 | sched.start() | 94 | sched.start() |
| 93 | # init schedule end | 95 | # init schedule end |
| 94 | 96 |
| @@ -6,9 +6,11 @@ | @@ -6,9 +6,11 @@ | ||
| 6 | # @Software: PyCharm | 6 | # @Software: PyCharm |
| 7 | import functools | 7 | import functools |
| 8 | import logging | 8 | import logging |
| 9 | +import threading | ||
| 9 | import time | 10 | import time |
| 10 | import uuid | 11 | import uuid |
| 11 | from concurrent.futures import ThreadPoolExecutor | 12 | from concurrent.futures import ThreadPoolExecutor |
| 13 | +from threading import Timer | ||
| 12 | 14 | ||
| 13 | from munch import Munch | 15 | from munch import Munch |
| 14 | 16 | ||
| @@ -43,13 +45,17 @@ class Monitor(callback.CallBack): | @@ -43,13 +45,17 @@ class Monitor(callback.CallBack): | ||
| 43 | self._socket = socket | 45 | self._socket = socket |
| 44 | Config.set('host', self._socket.ws_url) | 46 | Config.set('host', self._socket.ws_url) |
| 45 | 47 | ||
| 48 | + def go_login(self): | ||
| 49 | + threading.Thread(target=self._auto_login,args=()).start() | ||
| 50 | + | ||
| 46 | def _auto_login(self): | 51 | def _auto_login(self): |
| 47 | user_list = UserList.query(status=Status.ONLINE) | 52 | user_list = UserList.query(status=Status.ONLINE) |
| 48 | for user in user_list: | 53 | for user in user_list: |
| 49 | - print("执行登录", user) | ||
| 50 | - self.login(user.email, user.password, user.format_cookie()) | 54 | + print("自动登录->", user) |
| 55 | + self.login(user.email, user.password, user.format_cookie(), user.user_agent) | ||
| 51 | time.sleep(0.2) | 56 | time.sleep(0.2) |
| 52 | 57 | ||
| 58 | + | ||
| 53 | def _replace_call(self, client): | 59 | def _replace_call(self, client): |
| 54 | funcs = [x for x in dir(self) if x.startswith("on")] | 60 | funcs = [x for x in dir(self) if x.startswith("on")] |
| 55 | for fname in funcs: | 61 | for fname in funcs: |
| @@ -795,7 +795,18 @@ class FacebookClient(Client): | @@ -795,7 +795,18 @@ class FacebookClient(Client): | ||
| 795 | res = res['data']['node'] | 795 | res = res['data']['node'] |
| 796 | else: | 796 | else: |
| 797 | res = self._state._session.get(self._state.page_url + '/friends') | 797 | res = self._state._session.get(self._state.page_url + '/friends') |
| 798 | - res = parse_html.get_frient_div(res.text) | 798 | + if res.status_code == 200 and '/friends' in res.url: |
| 799 | + res = parse_html.get_frient_div(res.text) | ||
| 800 | + if not res: | ||
| 801 | + respone = { | ||
| 802 | + 'items': [], | ||
| 803 | + 'count': 0, | ||
| 804 | + 'ext_data': {}, | ||
| 805 | + 'has_next_page': False | ||
| 806 | + } | ||
| 807 | + return respone | ||
| 808 | + else: | ||
| 809 | + raise BaseException("网络访问异常,utl=", res.url) | ||
| 799 | edges = res['items']['edges'] | 810 | edges = res['items']['edges'] |
| 800 | count = res['items']['count'] | 811 | count = res['items']['count'] |
| 801 | friends = [] | 812 | friends = [] |
| @@ -183,6 +183,8 @@ def get_div_text(html): | @@ -183,6 +183,8 @@ def get_div_text(html): | ||
| 183 | 183 | ||
| 184 | 184 | ||
| 185 | def get_frient_div(text): | 185 | def get_frient_div(text): |
| 186 | + if not 'ProfileCometAppSectionFriendsList' in text: | ||
| 187 | + return None | ||
| 186 | b = bs4.BeautifulSoup(text, 'html.parser') | 188 | b = bs4.BeautifulSoup(text, 'html.parser') |
| 187 | script = b.find('script', string=re.compile(r'ProfileCometAppSectionFriendsList')) | 189 | script = b.find('script', string=re.compile(r'ProfileCometAppSectionFriendsList')) |
| 188 | a = re.findall(r'TimelineAppCollectionListRenderer",collection:(\{.*?\}\}\})', script.string)[0] | 190 | a = re.findall(r'TimelineAppCollectionListRenderer",collection:(\{.*?\}\}\})', script.string)[0] |
-
请 注册 或 登录 后发表评论