def add_to_db(adder, comments, verified, verified_user_id, is_rude): for parsed_args in comments: params = CSVDataUploader.make_site_comment_params( parsed_args, verified, verified_user_id, is_rude) if SiteComment.is_exist(adder, params.get('comment_id')): continue adder.add(SiteComment(params))
def load_comments_from_se_to_db(): def make_site_comment_params(comment, info): comment_id, post_id, body, creation_date, author_id, author_name = comment question_id, answer_id, post_author_id, post_author_name, score, title, post_creation_date = info return { "comment_id": comment_id, "question_id": question_id, "answer_id": answer_id, "post_author_id": post_author_id, "post_score": score, "title": title, "body": body, "processed_body": process_text(body), "creation_date": creation_date, "author_id": author_id, "author_name": author_name, "verified": None, "is_rude": False, "diff_with_post": (creation_date - post_creation_date).total_seconds() } last_one = SiteComment.last_comment() comments = get_recent_comments(last_one.creation_date) infos = dict() ids = [comment[1] for comment in comments] page_size = 20 counter = 0 while counter < len(ids): req_ids = ids[counter:counter + page_size] info = get_post_infos(req_ids) infos.update(info) counter += page_size adder = DBModelAdder() adder.start() for comment in comments: if SiteComment.is_exist(adder, comment[0]): continue adder.add( SiteComment( make_site_comment_params(comment, infos.get(comment[1])))) adder.done()
def add(adder, comments): for comment in comments: if SiteComment.is_exist(adder, comment.get("comment_id")): continue adder.add(SiteComment(comment))