Exemple #1
0
def article_test(article_url):
    Logging.info(u"article_test:")
    article = Article(article_url)
    article_id = article.get_article_id()
    print article_id
    title = article.get_article_title()
    print title
Exemple #2
0
def collection_test(collection_url):
    Logging.info(u"collection_test:")
    collection = Collection(collection_url)
    collection_id = collection.get_collection_id()
    print collection_id
    collection_name = collection.get_collection_name()
    print collection_name
    creator = collection.get_creator()
    print creator.get_user_id()
    answers = collection.get_answers()
    for answer in answers:
        print answer.get_answer_id()
Exemple #3
0
def topic_test(topic_url):
    Logging.info(u"topic_test:")
    topic = Topic(topic_url)
    topic_id = topic.get_topic_id()
    print topic_id
    topic_name = topic.get_topic_name()
    print topic_name
    question_num = topic.get_question_num()
    print question_num
    follower_num = topic.get_follower_num()
    print follower_num
    questions = topic.get_questions()
Exemple #4
0
def test_user(user_url):
    Logging.info(u"test_user:")
    user = User(user_url)
    print user.url
    for follower in user.get_followers():
        print follower.url

    answer_num = user.get_answer_num()
    print answer_num
    ask_num = user.get_ask_num()
    print ask_num
    followee_num = user.get_followee_num()
    article_num = user.get_articles_num()
    print article_num
    print followee_num
Exemple #5
0
def test_answer(answer_url):
    Logging.info(u"test_answer:")
    answer = Answer(answer_url)
    answer_id = answer.get_answer_id()
    print answer_id
    question_id = answer.get_question_id()
    print question_id
    author_id = answer.get_author_id()
    print author_id
    detail = answer.get_detail()
    print detail
    upvote_num = answer.get_upvote_num()
    print upvote_num
    visited_times = answer.get_visited_times()
    print visited_times
    print "Post time"+answer.get_post_time()
    print "Last edit time"+answer.get_last_edit_time()
Exemple #6
0
def spider(question):
    if not questionBloom.is_element_exist(question.get_question_id()):
        questionlock.acquire()
        questionBloom.insert_element(question.get_question_id())
        Worm_status.record_status("questionBloom", questionBloom)
        questionlock.release()
        DataBase.put_question_in_db(question)
        Logging.info("Topics of question id %s" % question.get_question_id())
        for topictag in question.get_topics():
            if not topicBloom.is_element_exist(topictag.get_topic_id()):
                DataBase.put_topic_in_db(topictag)
                topiclock.acquire()
                topicBloom.insert_element(topictag.get_topic_id())
                Worm_status.record_status("topicBloom", topicBloom)
                topiclock.release()
            DataBase.put_question_topic_in_db(question, topictag)

        Logging.info("Answers of question id %s" % question.get_question_id())
        for answer in question.get_answers():
            if not answerBloom.is_element_exist(answer.get_answer_id()):
                answerlock.acquire()
                answerBloom.insert_element(answer.get_answer_id())
                Worm_status.record_status("answerBloom", answerBloom)
                answerlock.release()
            if not userBloom.is_element_exist(answer.get_author_id()):
                DataBase.put_user_in_db(answer.get_author())
                userlock.acquire()
                userBloom.insert_element(answer.get_author_id())
                Worm_status.record_status("userBloom", userBloom)
                userlock.release()
            DataBase.put_answer_in_db(answer)
            for user in answer.get_upvoters():
                if not userBloom.is_element_exist(user.get_user_id()):
                    DataBase.put_user_in_db(user)
                    userlock.acquire()
                    userBloom.insert_element(user.get_user_id())
                    Worm_status.record_status("userBloom", userBloom)
                    userlock.release()
                DataBase.put_vote_in_db(answer, user)

        Logging.info("Follower of question id %s" % question.get_question_id())
        for follower in question.get_followers():
            if not userBloom.is_element_exist(follower.get_user_id()):
                DataBase.put_user_in_db(follower)
                userlock.acquire()
                userBloom.insert_element(follower.get_user_id())
                Worm_status.record_status("userBloom", userBloom)
                userlock.release()
            DataBase.put_follow_question_in_db(question, follower)
    else:
        Logging.debug("Exist Question")
Exemple #7
0
def test_topic(topic_url):
    Logging.info(u"topic_test:")
    topic = Topic(topic_url)
    topic.get_question_num()
    for topic in topic.get_child():
        print topic.get_topic_name()
Exemple #8
0
def question_test(question_url):
    Logging.info(u"question_test:")
    question = Question(question_url)
    print question.get_edit_time()