Example #1
0
    def run(self):
        common_logger.info('enter threading: %s' % self.thread_id)
        # page_html = HTTPUtils.get(self.url)
        page_html = requests.get(self.url).content
        self.roomid = int(response_parser.parse_room_id(page_html))
        server_ip, server_port = response_parser.parse_server_info(page_html)
        # self.login_request(server_ip, server_port)
        self.login_server(server_ip, server_port)

        main_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print 'connect'
        main_socket.connect((self.socket_ip, self.socket_port))
        # self.get_groupid(main_socket)
        print 'login'
        main_socket.send(socket_message.build(
            'type@=loginreq/username@=username/password@=password/roomid@={0}/'.format(self.roomid)))
        main_socket.recv(1024)
        print 'join'
        print 'gid=%s' % self.groupid
        main_socket.send(socket_message.build('type@=joingroup/rid@={0}/gid@={1}/'.format(self.roomid, self.groupid)))

        self.heart_thread = HeartThread(main_socket, 40)
        self.heart_thread.start()

        while not self.is_stop:
            userid, nickname, content = response_parser.parse_content(main_socket.recv(1024))
            post_time = datetime.datetime.utcnow()
            if userid != -1:
                # print 'nickname: ' + nickname + ' content: ' + content
                print '[room:%s][%s][userid:%s]%s: %s' % (self.roomid, post_time, userid, nickname, content)
                db_controller.save_danmu(userid, nickname, content, post_time, self.roomid)
Example #2
0
 def shutdown(self):
     common_logger.info('stoped thread: %s' % self.thread_id)
     self.heart_thread.shutdown()
     self.is_stop = True
Example #3
0
 def add_task(self, crawler_thread):
     common_logger.info('add task: %s' % crawler_thread.thread_id)
     self.running_tasks[crawler_thread.thread_id] = crawler_thread
     crawler_thread.start()