def question_answers(self, question_id): try: question = self.zhclient.question(question_id) record_time = self.logtime() answer_set = set() for answer in shield(question.answers): status = self.isdupicaterel("question_answers", "question_id", "answer_id", question.id, answer.id) if status == None: if answer.id not in answer_set: answer_set.add(answer.id) values = (question.id, question.title, answer.id, answer.author.id,record_time) self.cursor.execute("insert into question_answers(question_id,question_title,answer_id,author_id,record_time) VALUES (?,?,?,?,?)", values) self.dbcommit() print("正在处理", question.id, question.title, answer.id, answer.author.id) else: print("已存在,正在跳过") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass except ZhihuWarning: print("Pass the UnexpectedResponseException") pass
def user_topics(self, user_id): try: people = self.zhclient.people(user_id) record_time = self.logtime() topic_set = set() for topic in shield(people.following_topics): status = self.isdupicaterel("user_topics", "user_id", "topic_id", people.id, topic.id) if status == None: if topic.id not in topic_set: topic_set.add(topic.id) values = (people.id, people.name, topic.id,topic.name, record_time) self.cursor.execute( "insert into user_topics(user_id,user_name,topic_id,topic_name,record_time) VALUES (?,?,?,?,?)", values) self.dbcommit() print("正在处理", people.name ,topic.name) else: print("已存在,正在跳过") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass
def question_topics(self,question_id): try: question = self.zhclient.question(question_id) record_time = self.logtime() topic_set = set() for topic in shield(question.topics): status = self.isdupicaterel("question_topics", "question_id", "topic_id", question.id, topic.id) if status == None: if topic.id not in topic_set: topic_set.add(topic.id) values = (question.id,topic.id,topic.name,record_time) self.cursor.execute("insert into question_topics(question_id,topic_id,topic_name,record_time) VALUES (?,?,?,?)",values) self.dbcommit() print("正在处理", topic.name,question.title) else: print("已存在,正在跳过") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass
def user_users(self,user_id): try: people = self.zhclient.people(user_id) record_time = self.logtime() user_set = set() for follower in shield(people.followers,action=SHIELD_ACTION.PASS): status = self.isdupicaterel("user_users", "user_id", "user_follower_id", people.id, follower.id) if status == None: if follower.id not in user_set: user_set.add(follower.id) valus = (people.id,follower.id,record_time) self.cursor.execute("insert into user_users(user_id,user_follower_id,record_time) VALUES (?,?,?)",valus) self.dbcommit() print("正在处理",follower.name) else: print("已存在,正在跳过") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass
def topic_questions(self,topic_id): try: topic = self.zhclient.topic(topic_id) record_time = self.logtime() ques_set = set() for hot_ques in shield(topic.best_answers,action=SHIELD_ACTION.PASS): status = self.isdupicaterel("topic_questions", "topic_id", "question_id", topic.id, hot_ques.question.id) if status == None: if hot_ques.question.id not in ques_set: ques_set.add(hot_ques.question.id) values = (topic.id,topic.name,hot_ques.question.id,hot_ques.question.title,record_time) self.cursor.execute("insert into topic_questions(topic_id,topic_name,question_id,question_title,record_time) VALUES (?,?,?,?,?)" ,values) self.dbcommit() print("正在处理", hot_ques.question.id) else: print("已存在,正在跳过") pass except GetDataErrorException: print("Pass the GetDataErrorException") raise except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass
def question_users(self, question_id): try: question = self.zhclient.question(question_id) record_time = self.logtime() user_set = set() for follower in shield(question.followers,action=SHIELD_ACTION.PASS): status = self.isdupicaterel("question_users", "question_id", "user_id", question.id, follower.id) if status == None: if follower.id not in user_set: user_set.add(follower.id) values = (question.id, question.title, follower.id, follower.name,record_time) self.cursor.execute( "insert into question_users(question_id,question_title,user_id,user_name,record_time) VALUES (?,?,?,?,?)", values) self.dbcommit() print("正在处理",follower.name,question.title) else: print("已存在,正在跳过") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass
def topic_users(self,topic_id,start_at = 0): try: topic = self.zhclient.topic(topic_id) record_time = self.logtime() user_set = set() for follower in shield(topic.followers,start_at=start_at,action=SHIELD_ACTION.PASS): status = self.isdupicaterel("topic_users", "topic_id", "user_id", topic.id, follower.id) if status == None: if follower.id not in user_set: user_set.add(follower.id) values = (topic.id,topic.name,follower.id,follower.name,record_time) self.cursor.execute("insert into topic_users(topic_id,topic_name,user_id,user_name,record_time) VALUES (?,?,?,?,?)" ,values) self.dbcommit() print("正在处理",topic.name,follower.name) # time.sleep(0.3) else: print("已存在,正在跳过") pass except GetDataErrorException: print("Pass the GetDataErrorException") pass except UnexpectedResponseException: print("Pass the UnexpectedResponseException") pass