正在显示
5 个修改的文件
包含
44 行增加
和
16 行删除
| @@ -21,7 +21,7 @@ monitor.version = settings.get_version() | @@ -21,7 +21,7 @@ monitor.version = settings.get_version() | ||
| 21 | def server_replace(ws_url): | 21 | def server_replace(ws_url): |
| 22 | '''新开一个socket尝试连接新地址,存储在临时变量里''' | 22 | '''新开一个socket尝试连接新地址,存储在临时变量里''' |
| 23 | monitor._temp_socket = MessageSocketClient(connect_success, message_receive) | 23 | monitor._temp_socket = MessageSocketClient(connect_success, message_receive) |
| 24 | - monitor._temp_socket.connect(ws_url, reconnect=False) # 失败不重试 | 24 | + monitor._temp_socket.connect(ws_url, monitor._name, monitor._imei, reconnect=False) # 失败不重试 |
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | def message_receive(message): | 27 | def message_receive(message): |
| @@ -71,5 +71,7 @@ def connect_success(sock): | @@ -71,5 +71,7 @@ def connect_success(sock): | ||
| 71 | 71 | ||
| 72 | def run(): | 72 | def run(): |
| 73 | socket = MessageSocketClient(connect_success, message_receive) | 73 | socket = MessageSocketClient(connect_success, message_receive) |
| 74 | - socket.connect(**settings.get_server()) | 74 | + conf = settings.get_server() |
| 75 | + conf.update({'url': monitor._host, 'name': monitor._name, 'uuid': monitor._imei}) | ||
| 76 | + socket.connect(**conf) | ||
| 75 | ioloop.IOLoop.instance().start() | 77 | ioloop.IOLoop.instance().start() |
| @@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor | @@ -12,6 +12,7 @@ from concurrent.futures import ThreadPoolExecutor | ||
| 12 | 12 | ||
| 13 | from munch import Munch | 13 | from munch import Munch |
| 14 | 14 | ||
| 15 | +from conf import settings | ||
| 15 | from core import callback, command | 16 | from core import callback, command |
| 16 | from lib import control_server | 17 | from lib import control_server |
| 17 | from lib.common import TaskStatus | 18 | from lib.common import TaskStatus |
| @@ -33,13 +34,14 @@ class Monitor(callback.CallBack): | @@ -33,13 +34,14 @@ class Monitor(callback.CallBack): | ||
| 33 | self._listenlist = dict() | 34 | self._listenlist = dict() |
| 34 | self._imei = Config.get('imei', lambda: uuid.uuid1().hex) | 35 | self._imei = Config.get('imei', lambda: uuid.uuid1().hex) |
| 35 | self._name = Config.get('name', control_server.get_init_name) | 36 | self._name = Config.get('name', control_server.get_init_name) |
| 36 | - self._host = None | ||
| 37 | - self.version = '1.0.0' | 37 | + self._host = Config.get('host', lambda: settings.get_server()['url']) |
| 38 | + self.version = None | ||
| 38 | self.executor = ThreadPoolExecutor(50, 'task_thread') | 39 | self.executor = ThreadPoolExecutor(50, 'task_thread') |
| 39 | self.init_config = {} | 40 | self.init_config = {} |
| 40 | 41 | ||
| 41 | def bind(self, socket): | 42 | def bind(self, socket): |
| 42 | self._socket = socket | 43 | self._socket = socket |
| 44 | + Config.set('host', self._socket.ws_url) | ||
| 43 | 45 | ||
| 44 | def _auto_login(self): | 46 | def _auto_login(self): |
| 45 | user_list = UserList.query(status=Status.ONLINE) | 47 | user_list = UserList.query(status=Status.ONLINE) |
| @@ -30,7 +30,7 @@ def post_terminal_info(name, source_ws, num, version): | @@ -30,7 +30,7 @@ def post_terminal_info(name, source_ws, num, version): | ||
| 30 | data['ip'] = _host | 30 | data['ip'] = _host |
| 31 | print(data) | 31 | print(data) |
| 32 | try: | 32 | try: |
| 33 | - r = requests.post(SERVER + '/post_terminal_info', data, timeout=1) | 33 | + r = requests.post(SERVER + '/post_terminal_info', json=data, timeout=1) |
| 34 | new_ws = r.json().get('data', {}).get('ws', source_ws) | 34 | new_ws = r.json().get('data', {}).get('ws', source_ws) |
| 35 | except: | 35 | except: |
| 36 | new_ws = source_ws | 36 | new_ws = source_ws |
| @@ -80,7 +80,7 @@ class PCState(State): | @@ -80,7 +80,7 @@ class PCState(State): | ||
| 80 | 80 | ||
| 81 | user_id = get_user_id(session) | 81 | user_id = get_user_id(session) |
| 82 | 82 | ||
| 83 | - r = session.get(_util.prefix_url("/"),timeout=10) | 83 | + r = session.get(_util.prefix_url("/"), timeout=10) |
| 84 | 84 | ||
| 85 | b = parse_html.show_home_page(r.text) | 85 | b = parse_html.show_home_page(r.text) |
| 86 | logout_menu = b.find('div', id='logoutMenu') | 86 | logout_menu = b.find('div', id='logoutMenu') |
| @@ -451,15 +451,16 @@ class FacebookClient(Client): | @@ -451,15 +451,16 @@ class FacebookClient(Client): | ||
| 451 | :return (ID,Name) | 451 | :return (ID,Name) |
| 452 | ''' | 452 | ''' |
| 453 | total_ids = [] | 453 | total_ids = [] |
| 454 | - ids, names, gender = [], [], [] | 454 | + res = [] |
| 455 | 455 | ||
| 456 | while True: | 456 | while True: |
| 457 | - if not (ids or names): | ||
| 458 | - ids, names, gender = self._pymk_request(total_ids) | 457 | + if not res: |
| 458 | + res = self._pymk_request(total_ids) | ||
| 459 | + ids = [x['fbid'] for x in res] | ||
| 459 | total_ids.extend(ids) | 460 | total_ids.extend(ids) |
| 460 | if not ids: | 461 | if not ids: |
| 461 | return | 462 | return |
| 462 | - sub = (ids.pop(0), names.pop(0), gender.pop(0)) | 463 | + sub = res.pop(0) |
| 463 | yield sub | 464 | yield sub |
| 464 | 465 | ||
| 465 | def _pymk_request(self, total_ids: list): | 466 | def _pymk_request(self, total_ids: list): |
| @@ -527,17 +528,20 @@ class FacebookClient(Client): | @@ -527,17 +528,20 @@ class FacebookClient(Client): | ||
| 527 | '''发出的加好友请求''' | 528 | '''发出的加好友请求''' |
| 528 | url = None | 529 | url = None |
| 529 | empty = False | 530 | empty = False |
| 530 | - ids, names = [], [] | 531 | + res = [] |
| 531 | 532 | ||
| 532 | while True: | 533 | while True: |
| 533 | - if not (ids or names): | 534 | + if not res: |
| 534 | if empty: | 535 | if empty: |
| 535 | return | 536 | return |
| 536 | - ids, names, url = self._outgoingRequest(url) | 537 | + res, url = self._outgoingRequest(url) |
| 537 | if not url: | 538 | if not url: |
| 538 | empty = True | 539 | empty = True |
| 539 | - sub = (ids.pop(0), names.pop(0)) | ||
| 540 | - yield sub | 540 | + if not res: |
| 541 | + empty = True | ||
| 542 | + else: | ||
| 543 | + sub = res.pop(0) | ||
| 544 | + yield sub | ||
| 541 | 545 | ||
| 542 | def _outgoingRequest(self, url=None, require_gender=True): | 546 | def _outgoingRequest(self, url=None, require_gender=True): |
| 543 | if url: | 547 | if url: |
| @@ -713,3 +717,18 @@ class FacebookClient(Client): | @@ -713,3 +717,18 @@ class FacebookClient(Client): | ||
| 713 | 717 | ||
| 714 | def get_user_agent(self): | 718 | def get_user_agent(self): |
| 715 | return self._state._session.headers.get('User-Agent', random.choice(_util.USER_AGENTS)) | 719 | return self._state._session.headers.get('User-Agent', random.choice(_util.USER_AGENTS)) |
| 720 | + | ||
| 721 | + def searchForUserByFilter(self, name=None, city=None): | ||
| 722 | + url = 'https://www.facebook.com/search/top/' | ||
| 723 | + data = {'q': 'angel', | ||
| 724 | + 'ref': 'side_filter', | ||
| 725 | + 'epa': 'FILTERS', | ||
| 726 | + 'filters': 'eyJycF9sb2NhdGlvbiI6IntcIm5hbWVcIjpcImxvY2F0aW9uXCIsXCJhcmdzXCI6XCIxMDYyNjI4ODI3NDU2OThcIn0ifQ==', | ||
| 727 | + 'ajaxpipe': '1', | ||
| 728 | + 'ajaxpipe_token': 'AXjhI9q4VDQji6Ox', | ||
| 729 | + 'quickling[version]': '1001720869;0;' | ||
| 730 | + } | ||
| 731 | + # f = furl.furl(url).add(data) | ||
| 732 | + # print(f.url) | ||
| 733 | + res=self._state._get('https://www.facebook.com/search/people/?q=angel&epa=FILTERS&filters=eyJjaXR5Ijoie1wibmFtZVwiOlwidXNlcnNfbG9jYXRpb25cIixcImFyZ3NcIjpcIjEwNjI2Mjg4Mjc0NTY5OFwifSJ9&ref=side_filter',{}) | ||
| 734 | + print(res) |
| @@ -42,6 +42,8 @@ class WebSocketClient(object): | @@ -42,6 +42,8 @@ class WebSocketClient(object): | ||
| 42 | self._connect_status = self.CONNECTING | 42 | self._connect_status = self.CONNECTING |
| 43 | 43 | ||
| 44 | headers = httputil.HTTPHeaders({ | 44 | headers = httputil.HTTPHeaders({ |
| 45 | + 'Clientname': self._clientname, | ||
| 46 | + 'ClientUUID': self._clientuuid, | ||
| 45 | 'Content-Type': APPLICATION_JSON, | 47 | 'Content-Type': APPLICATION_JSON, |
| 46 | 'Origin': '*', | 48 | 'Origin': '*', |
| 47 | }) | 49 | }) |
| @@ -145,10 +147,13 @@ class MessageSocketClient(WebSocketClient): | @@ -145,10 +147,13 @@ class MessageSocketClient(WebSocketClient): | ||
| 145 | self.server_replace(ws_url) | 147 | self.server_replace(ws_url) |
| 146 | self._later_handler['move_server'] = self._io_loop.call_later(random.randint(30, 30), self.auto_move_server) | 148 | self._later_handler['move_server'] = self._io_loop.call_later(random.randint(30, 30), self.auto_move_server) |
| 147 | 149 | ||
| 148 | - def connect(self, url, reconnect=True, reconnect_interval=3): | 150 | + def connect(self, url, name, uuid, reconnect=True, reconnect_interval=3): |
| 149 | self.ws_url = url | 151 | self.ws_url = url |
| 150 | self.auto_reconnet = reconnect | 152 | self.auto_reconnet = reconnect |
| 151 | self.reconnect_interval = reconnect_interval | 153 | self.reconnect_interval = reconnect_interval |
| 154 | + self._clientname=name | ||
| 155 | + self._clientuuid=uuid | ||
| 156 | + | ||
| 152 | super(MessageSocketClient, self).connect(self.ws_url) | 157 | super(MessageSocketClient, self).connect(self.ws_url) |
| 153 | 158 | ||
| 154 | def on_connection_success(self): | 159 | def on_connection_success(self): |
-
请 注册 或 登录 后发表评论