Пример #1
0
def parse_comment(comment_info: BeautifulSoup):
    time_str = beautify(comment_info.find(attrs={"id": "comment_time"}).text)
    time = datetime.strptime(time_str, "%Y-%m-%d")
    author = comment_info.find(attrs={"id": "comment_author"}).text
    attrs_li = comment_info.find(attrs={
        "id": "comment_attrs"
    }).find_all(name="li")
    attrs = {
        "is_hot": beautify(attrs_li[0].text).split(" ")[1] == "True",
        "attitude": int(beautify(attrs_li[1].text).split(" ")[1])
    }
    content = comment_info.find(attrs={"id": "comment_content"}).text
    analyse = parse_analyse_info(
        comment_info.find(attrs={"id": "comment_analyse_info"}))
    return Comment(time, content, author, attrs=attrs)
Пример #2
0
def flit(src_dir: str, dest_dir: str, rule):
    src_news = util.news_from_local_file(src_dir)
    for raw_news in src_news:
        if rule(raw_news):
            util.to_mark_down(raw_news.to_string(), dest_dir,
                              "{time}_{title}".format(time=raw_news.time.strftime("%Y-%m-%d"),
                                                      title=util.beautify(raw_news.title)))