使用场景
Trading System 读书笔记,哈哈,其实就是用来看英文文档用的,为什么要用这款软件呢?因为在Ubuntu上用自带的软件打开pdf后,把内容拷贝下来后,格式是有点混乱的,再放在google translate里面翻译时就会导致不连贯而使结果不准确。
主要有以下几点:
- 一个句子被隔断了
- 一个断落该换行时而没被换行
- 有些字符后面拷贝出来后某名的给你在后面加了空格,导致一个单词一分为二
- 隔页拷贝的时候,会把页脚和页眉也拷贝进去,关键还是给你夹在句子当中的
使用前提
操作系统:Ubuntu
书箱格式:Pdf
软件:Ubuntu自带阅读软件
如何使用
- 提前打开软件。
./TranPdfUbuntu.py
- 在阅读软件里面把内容拷贝好
- 按Ctrl+B。这个操作过后,内容在剪切板里已经格式化好了
- 粘贴到google translate里面
代码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
about key binder
https://gist.github.com/lesthack/1302380
http://programtalk.com/python-examples/keybinder.bind/
"""
import keybinder
import gtk
TRAN_KEY_STR = "<Ctrl>B"
EXIT_KEY_STR = "<Ctrl><Alt>C"
COUNT = 0
BOOK_NAME = "TRADING SYSTEMS AND METHODS"
TITLES = ["Introduction", "Basic Concepts and Calculations", "Charting", "Cycle Analysis",
"Volume, Open Interest and Breadth", "Spreads and Arbitrage", "Behavioral Techniques",
"Pattern Recognition", "Day Trading"]
FUS_STR = "|!@#"
def ltrim_number(strr):
strr = strr.rstrip()
for i in range(1, 9):
if not is_str_int(strr[-i]):
break
return strr[0:len(strr) - i + 1] + " "
def title_end_with(text):
for title in TITLES:
if text.endswith(title+" "):
return title
return ""
def is_str_int(string):
try:
int(string)
return True
except ValueError:
# Handle the exception
return False
def callback_exit(user_data):
print ''
print 'traslate %d times' % COUNT
print "unbinding ..."
keybinder.unbind(TRAN_KEY_STR)
keybinder.unbind(EXIT_KEY_STR)
gtk.main_quit()
print "exited"
def callback(user_data):
# get txt from clipboard
src_txt = gtk.clipboard_get().wait_for_text()
des_txt = ""
# translate
origin_split = src_txt.split("\n")
for line in origin_split:
# fix words
line = line.replace("fi ", "fi").replace("fl ", "fl")
# clear titles
if line == BOOK_NAME:
des_txt = ltrim_number(des_txt)
if des_txt.endswith(". "):
des_txt += "\n"
# clear page num
elif line.__len__() <= 4 and is_str_int(line):
title = title_end_with(des_txt)
des_txt = des_txt.rstrip() + FUS_STR
des_txt = des_txt.replace(title + FUS_STR, " ")
if des_txt.endswith(". "):
des_txt += "\n"
elif line.__len__() == 1 and line.isupper() and des_txt.__len__() == 0:
des_txt += line
elif line.endswith("-"):
line = line[0:len(line) - 1]
des_txt += line
elif line.endswith("."):
des_txt += line + "\n"
else:
des_txt += line + " "
# copy txt to clipboard and des txt
gtk.clipboard_get().set_text(des_txt)
# print count
global COUNT
COUNT += 1
# print COUNT,
if __name__ == '__main__':
keybinder.bind(EXIT_KEY_STR, callback_exit, "Keystring %s (user data)" % EXIT_KEY_STR)
keybinder.bind(TRAN_KEY_STR, callback, "Keystring %s (user data)" % TRAN_KEY_STR)
print TRAN_KEY_STR, '->translate \n', EXIT_KEY_STR, '->exit'
gtk.main()
Comments
comments powered by Disqus