作者 lemon

修复好友列表的无好友获取异常问题

... ... @@ -4,6 +4,7 @@
# @Author : Lemon
# @File : core.py
# @Software: PyCharm
import datetime
import functools
import json
... ... @@ -89,6 +90,7 @@ def run():
sched = TornadoScheduler()
sched.add_job(monitor._socket.sendheartbeat, 'interval', seconds=25)
sched.add_job(monitor._socket.auto_move_server, 'interval', seconds=31)
sched.add_job(monitor.go_login, next_run_time=datetime.datetime.now() + datetime.timedelta(seconds=5))
sched.start()
# init schedule end
... ...
... ... @@ -6,9 +6,11 @@
# @Software: PyCharm
import functools
import logging
import threading
import time
import uuid
from concurrent.futures import ThreadPoolExecutor
from threading import Timer
from munch import Munch
... ... @@ -43,13 +45,17 @@ class Monitor(callback.CallBack):
self._socket = socket
Config.set('host', self._socket.ws_url)
def go_login(self):
threading.Thread(target=self._auto_login,args=()).start()
def _auto_login(self):
user_list = UserList.query(status=Status.ONLINE)
for user in user_list:
print("执行登录", user)
self.login(user.email, user.password, user.format_cookie())
print("自动登录->", user)
self.login(user.email, user.password, user.format_cookie(), user.user_agent)
time.sleep(0.2)
def _replace_call(self, client):
funcs = [x for x in dir(self) if x.startswith("on")]
for fname in funcs:
... ...
... ... @@ -795,7 +795,18 @@ class FacebookClient(Client):
res = res['data']['node']
else:
res = self._state._session.get(self._state.page_url + '/friends')
res = parse_html.get_frient_div(res.text)
if res.status_code == 200 and '/friends' in res.url:
res = parse_html.get_frient_div(res.text)
if not res:
respone = {
'items': [],
'count': 0,
'ext_data': {},
'has_next_page': False
}
return respone
else:
raise BaseException("网络访问异常,utl=", res.url)
edges = res['items']['edges']
count = res['items']['count']
friends = []
... ...
... ... @@ -183,6 +183,8 @@ def get_div_text(html):
def get_frient_div(text):
if not 'ProfileCometAppSectionFriendsList' in text:
return None
b = bs4.BeautifulSoup(text, 'html.parser')
script = b.find('script', string=re.compile(r'ProfileCometAppSectionFriendsList'))
a = re.findall(r'TimelineAppCollectionListRenderer",collection:(\{.*?\}\}\})', script.string)[0]
... ...