Beispiel #1
0
def essence_article(content, warehouse):
    """获取必要的 msg_dict 信息封装成一个 Article 对象,并生成 markdown 文件"""
    author = content['author']['name']
    avatar = content['author']['avatar_url_template'].replace(
        const.AVATAR_SIZE_R, const.AVATAR_SIZE_A)
    author_page = const.AUTHOR_PAGE_URL.format(content['author']['url_token'])
    title = content['title']
    original_url = content['url']
    date = timer.timestamp_to_date(content['created'])
    try:
        # 有些文章没有背景大图,需要做空白处理
        background = re.sub(r'[^_]+?(?=.jpg)', 'r', content['image_url'])
    except KeyError:
        background = ''
    msg_dict = {
        'author': author,
        'author_avatar_url': avatar,
        'author_page': author_page,
        'title': title,
        'original_url': original_url,
        'created_date': date,
        'background': background
    }
    article_content = BeautifulSoup(content['content'], 'lxml').body
    article = document.Article(article_content, msg_dict)
    article.make_markdown(warehouse)
    print(article.article_msg())
Beispiel #2
0
def essence_answer(content, warehouse):
    """获取必要的 msg_dict 信息封装成一个 Answer 对象,并生成 markdown 文件"""
    author = content['author']['name']
    avatar = content['author']['avatar_url_template'].replace(
        const.AVATAR_SIZE_R, const.AVATAR_SIZE_A)
    author_page = const.AUTHOR_PAGE_URL.format(content['author']['url_token'])
    title = content['question']['title']
    question_id = content['question']['id']
    answer_id = content['id']
    original_url = const.ANSWER_URL.format(question_id, answer_id)
    date = timer.timestamp_to_date(content['created_time'])
    voteup = content['voteup_count']
    msg_dict = {
        'author': author,
        'author_avatar_url': avatar,
        'author_page': author_page,
        'title': title,
        'original_url': original_url,
        'created_date': date,
        'voteup': voteup
    }
    answer_content = BeautifulSoup(content['content'], 'lxml').body
    answer = document.Answer(answer_content, msg_dict)
    answer.make_markdown(warehouse)
    print(answer.answer_msg())
Beispiel #3
0
def article_msg(content):
    original_url = content['url']
    title = content['title']
    background_image = content['image_url']
    date = timer.timestamp_to_date(content['created'])
    article_dict = {'author': user_msg_dict['name'], 'author_avatar_url': user_msg_dict['author_avatar_url'],
                    'author_page': user_msg_dict['author_page'], 'title': title,
                    'original_url': original_url, 'created_date': date, 'background': background_image}
    return document.Meta(**article_dict)
Beispiel #4
0
def answer_msg(content):
    voteup = content['voteup_count']
    title = content['question']['title']
    question_id = content['question']['id']
    answer_id = content['id']
    original_url = const.ANSWER_URL.format(question_id, answer_id)
    date = timer.timestamp_to_date(content['created_time'])
    answer_dict = {'author': user_msg_dict['name'], 'author_avatar_url': user_msg_dict['author_avatar_url'],
                   'author_page': user_msg_dict['author_page'], 'title': title,
                   'original_url': original_url, 'created_date': date, 'voteup': voteup}
    return answer_dict
Beispiel #5
0
def article_msg(content):
    original_url = const.ARTICLE_URL.format(content['id'])
    title = content['title']
    background_image = content['image_url']
    date = timer.timestamp_to_date(content['created'])
    author = content['author']['name']
    author_page = const.AUTHOR_PAGE_URL.format(content['author']['url_token'])
    avatar = content['author']['avatar_url']
    article_dict = {'author': author, 'author_avatar_url': avatar, 'author_page': author_page, 'title': title,
                    'original_url': original_url, 'created_date': date, 'background': background_image}
    return document.Meta(**article_dict)
Beispiel #6
0
def article_msg(content):
    article_dict = dict()

    article_dict['original_url'] = const.ARTICLE_URL.format(content['id'])
    article_dict['title'] = content['title']
    article_dict['background'] = content['image_url']
    article_dict['created_date'] = timer.timestamp_to_date(content['created'])
    article_dict['author'] = content['author']['name']
    article_dict['author_page'] = const.AUTHOR_PAGE_URL.format(
        content['author']['url_token'])
    article_dict['author_avatar_url'] = content['author']['avatar_url']
    return document.Meta(**article_dict)