📚
Reading Notes
  • Introduction
  • Part 1
    • 美国宪政历程
    • 看见
    • 重新发现社会
    • 文化和价值
    • 荒原狼
    • 观念的水位
    • 刀锋
    • 一个人的村庄
    • 其他
  • Part 2
    • 悦读经典计划
    • 看不见的城市
    • 美的历程
    • 乡土中国·生育制度
  • Part 3
    • 城门开
    • 南京传
    • 古都·雪国
    • 查令十字街84号
    • 草莓人生
    • 四个春天
    • 有如候鸟
    • 不识字的人
    • 雨
    • 大雪将至
    • 云边有个小卖部
    • 是枝裕和人间三部曲
    • 在中途换飞机的时候
    • 平凡的世界
    • 爱的24则运算
    • 金阁寺
    • 读诗札记 : 夏目漱石的汉诗
  • Part 4
    • 契诃夫短篇小说精选
    • 失物之书
    • 博尔赫斯全集·诗歌卷
    • 病隙碎笔
    • 疑问集
    • 花与舌头
    • 二十首情诗和一首绝望的歌
    • 二十亿光年的孤独
    • 古诗词摘抄
    • 宴后
    • 我与地坛
    • 泰戈尔诗选
    • 文史补录
    • 苏菲的世界
    • 普希金诗选
    • 人间草木
    • 围城
    • 文化苦旅
    • 西川的诗
    • 云雀叫了一整天
    • 我以为,能与你到老
    • 草叶集
    • 沙之书
    • 夜空总有最大密度的蓝色
    • 食指的诗
    • 青春诗会·三十年诗选
    • 深浅·西川诗文录
    • 骆一禾的诗
    • 海子的诗
    • 骆一禾 海子 兄弟诗抄
    • 鼠疫
    • 木心诗选
    • 舒婷的诗
    • 顾城的诗
  • Part 5
    • 余光中文集
    • 我们仨
    • 巨鲸歌唱
    • 顾城的诗 顾城的画
    • 张枣的诗
    • 昌耀的诗
    • 当诗歌忘记我们
    • 当我终于变得沉默
    • 在夜晚的高原上
    • 落在纸上的雪
    • 千只鹤 波千鸟 伊豆的舞女
    • 挪威的森林
    • 且听风吟 1973年的弹子球 寻羊冒险记
    • 舞!舞!舞!
    • 在黄昏起飞
    • 海边的卡夫卡
    • 倾城之恋
    • 不能承受的生命之轻
    • 百年孤独
    • 德米安
    • 玻璃球游戏
    • 刚刚
    • 谷川的诗
  • Part 6
    • 1Q84
    • 丰饶之海
    • 世界尽头与冷酷仙境
    • 国境以南,太阳以西
    • 斯普特尼克恋人
    • 红玫瑰与白玫瑰
    • 半生缘
    • 小团圆
    • 沉默的经典诗歌译丛
    • 诗是承载生命重量的礼物
  • Appendix
    • Python Script for Extracting Clippings
    • Bash Script for Processing OCR Outputs
Powered by GitBook
On this page
  1. Appendix

Python Script for Extracting Clippings

#!/usr/bin/env python

# Usage: python extractClippings.py -i "My Clippings.txt" -b "路遥全集" -o "平凡的世界" -a "路遥" -t "2020-09 ~ 10"
# Latest update: 9/30/2024

import argparse
import re


def get_opt():
    group = argparse.ArgumentParser()

    group.add_argument(
        "-i", "--input", help="input clipping file's name", required=True
    )
    group.add_argument("-b", "--book", help="specified book's name", required=True)
    group.add_argument("-o", "--output", help="output file's name", required=True)
    group.add_argument("-a", "--author", help="author's name", required=True)
    group.add_argument("-t", "--time", help="time information", required=True)

    return group.parse_args()


opts = get_opt()
i = opts.input
b = opts.book
o = opts.output
a = opts.author
t = opts.time

file = open(i, "r", encoding="utf-8")
text = []
for line in file:
    if line != "\n" and line != "==========\n" and len(re.findall("^-", line)) == 0:
        text.append(line)
    if len(re.findall("Bookmark|书签", line)) != 0:
        text.append(line)

md = open("{}.md".format(o), "a", encoding="utf-8")
md.write("# {}\n> {}  \n> {}\n\n".format(o, a, t))

out = dict()
count = 1
for j in range(0, len(text), 2):
    if len(re.findall(b, text[j])) != 0:
        out[str(count)] = text[j + 1].replace(" ", "  \n")
        # this replacement is for poems only, but for bookmarks,
        # it may make some errors, just delete the error parts
        # as the bookmarks are not to be kept
        count += 1

for key, value in out.items():
    md.write("{}. {}".format(key, value))
PreviousAppendixNextBash Script for Processing OCR Outputs

Last updated 8 months ago