Exemple #1
0
    def update_question_insert_answer(self, question_id):
        change_question_status(db=self.db, question_id=question_id, status=FLAG.IN_USE)
        log.info("Updating untouched question {}".format(question_id))

        # Update question detail
        question_url = 'http://www.zhihu.com/question/' + question_id
        question_content = self.session.get(question_url).content.decode('utf-8')

        q_soup = BeautifulSoup(question_content, BS_PARSER)
        if type(q_soup.find(Magic.Question.title)) is not None:
            self.update_question_detail(q_soup, question_id)
        else:
            return  # 404

        # First 50 answers
        answers = q_soup.findAll('div', class_=Magic.Question.answer_div)
        if len(answers) > 0:
            for answer in answers:
                answer_id = int(Magic.answer_id_in_answer.findall(str(answer))[0])

                # TODO: save different version?
                # if self.db.answers.find({'answer_id': answer_id}).count() == 1:
                #     continue  # jump by this answer

                author, comments_count, content = self.process_answer(answer)
                insert_answer(self.db, answer_id, author, question_id, comments_count, content)

        # Users
        users = set(Magic.Question.mentioned_userid.findall(str(question_content)))
        for user in users:
            insert_new_user(self.db, user)

        change_question_status(db=self.db, question_id=question_id, status=FLAG.FINISHED)
Exemple #2
0
    def __init__(self):
        self.db = db_client
        self.session = get_or_create_session()

        # Seed user and necessary index
        insert_new_user(self.db, user_id=Magic.seed_user)

        self.db.answers.ensure_index("answer_id")
        self.db.answers.ensure_index("author")
        self.db.answers.ensure_index("relate_question")
        self.db.questions.ensure_index("question_id")
        self.db.questions.ensure_index("touched")
        self.db.users.ensure_index("touched")
        self.db.users.ensure_index("user_id")
Exemple #3
0
    def __init__(self):
        self.db = db_client
        self.loop = asyncio.get_event_loop()

        # Seed user and necessary index
        insert_new_user(self.db, user_id=Magic.seed_user)

        self.db.answers.ensure_index("answer_id")
        self.db.answers.ensure_index("author")
        self.db.answers.ensure_index("relate_question")
        self.db.questions.ensure_index("question_id")
        self.db.questions.ensure_index("touched")
        self.db.users.ensure_index("touched")
        self.db.users.ensure_index("user_id")
Exemple #4
0
def register():
    if session.get('registered'):
        return redirect(url_for('home'))

    accounttype = int( request.form.get('accounttype') )

    user_data = session['user_data']
    
    db.insert_new_user(
        user_data['user_id'],
        user_data['first_name'],
        user_data['last_name'],
        user_data['email'],
        user_data['image_url'],
        accounttype
    )
    session['registered'] = True                
    
    return "200"
Exemple #5
0
def set_up():
	db.create_db()
	welcome_text = '''
(\__/)
(•ㅅ•)
/   づ ♥
WELCOME INTO YOUR NEXT LEVEL!
-----------------------------'''
	print(Fore.BLUE  + Style.BRIGHT + welcome_text + Style.RESET_ALL)
	print(Fore.CYAN + Style.BRIGHT + str(datetime.date.today()) + ", " +
		calendar.day_name[datetime.datetime.today().weekday()] + Style.RESET_ALL)
	print(Fore.MAGENTA + Back.WHITE + Style.BRIGHT + "\n Oooh! It seems we got a new sweet user ♥‿♥ \n" + Style.RESET_ALL )
	user = read_configration()
	user.id = db.insert_new_user(user)
	return user