Skip to content

Instantly share code, notes, and snippets.

@XuankangLin
Created December 22, 2015 20:53
Show Gist options
  • Save XuankangLin/704ca901e7b30840e214 to your computer and use it in GitHub Desktop.
Save XuankangLin/704ca901e7b30840e214 to your computer and use it in GitHub Desktop.
Strip those spaces in copied texts from Kindle app
#!/usr/bin/python
import sys
import os
""" This is for concatenating all the separeted words from Kindle app.. I just
want them be merged again..
Input (copied directly from Kindle app):
罗马 帝国 的 东西 分离, 是“ 东部” 分 了 出去。 东 罗马 帝国 被 希腊人 建成 了 单一 基督教 帝国, 而 西 罗马 帝国 虽说 也是 拉丁人 的 基督教 帝国, 但 异教 时代 的 罗马 色彩 依然 浓重。 因此, 东 罗马 帝国 也许 并没有 视 西 罗马 帝国 与 自己 性质 相同。 这样一来, 罗马 世界 分裂 为 东西 两半 就成 定论 了。
盐野七生 (2013-08-15). 罗马人的故事15:罗马世界的终曲 (开放历史系列) (Kindle Locations 552-555). 中信出版社. Kindle Edition.
Output (copied to pasteboard):
罗马帝国的东西分离,是“东部”分了出去。东罗马帝国被希腊人建成了单一基督教帝国,而西罗马帝国虽说也是拉丁人的基督教帝国,但异教时代的罗马色彩依然浓重。因此,东罗马帝国也许并没有视西罗马帝国与自己性质相同。这样一来,罗马世界分裂为东西两半就成定论了。
"""
# first will be reformat.py
args = sys.argv[1:]
# I just don't want any spaces, they are automatically separated by shell
merged = ''.join(args)
# copy to pasteboard
os.system("echo '%s' | pbcopy" % merged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment