Exemplo n.º 1
0
def save_article(article, folder='test', overwrite=True):
  article = parse_article(article)

  title = zhihu_article_title(article)
  save_path = folder + '/' + remove_invalid_char(title) + '.md'
  if not overwrite:
    if os.path.exists(save_path):
      log('already exist {}'.format(save_path))
      return save_path

  data = fetch_zhihu_article(article=article)
  rendered = fill_full_content(data)

  with open(save_path, 'w', encoding='utf-8') as f:
    f.write(rendered)
    log('write {} done'.format(save_path))

  # 本地存储, 需要抓取所有附图
  fetch_images_for_markdown(save_path)
  return save_path
Exemplo n.º 2
0
def save_answer(answer, folder='test', overwrite=True):
  answer = parse_answer(answer)

  title = answer.question.title + ' - ' + answer.author.name + '的回答'
  save_path = folder + '/' + remove_invalid_char(title) + '.md'
  if not overwrite:
    if os.path.exists(save_path):
      log('already exist {}'.format(save_path))
      return save_path

  data = fetch_zhihu_answer(answer=answer)
  rendered = fill_full_content(data)

  with open(save_path, 'w', encoding='utf-8') as f:
    f.write(rendered)
    log('write {} done'.format(save_path))

  # 本地存储, 需要抓取所有附图
  fetch_images_for_markdown(save_path)
  return save_path