Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
BookerTrans
提交
7b53e032
B
BookerTrans
项目概览
OpenDocCN
/
BookerTrans
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
BookerTrans
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7b53e032
编写于
4月 29, 2020
作者:
W
wizardforcel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add timeout
上级
1ff8aa90
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
17 addition
and
5 deletion
+17
-5
BookerTrans/__init__.py
BookerTrans/__init__.py
+1
-1
BookerTrans/__main__.py
BookerTrans/__main__.py
+3
-0
BookerTrans/api.py
BookerTrans/api.py
+5
-2
README.md
README.md
+3
-2
history.md
history.md
+5
-0
未找到文件。
BookerTrans/__init__.py
浏览文件 @
7b53e032
...
...
@@ -10,7 +10,7 @@ from . import config
__author__
=
"ApacheCN"
__email__
=
"apachecn@163.com"
__license__
=
"SATA"
__version__
=
"2020.04.29"
__version__
=
"2020.04.29
.1
"
RE_CODE
=
r
'<(pre|code)[^>]*?>[\s\S]*?</\1>'
RE_TAG
=
r
'<[^>]*?>'
...
...
BookerTrans/__main__.py
浏览文件 @
7b53e032
# coding: utf-8
import
os
from
os
import
path
from
argparse
import
ArgumentParser
from
.
import
trans_html
,
config
,
api
,
__version__
...
...
@@ -29,6 +30,7 @@ def main():
parser
.
add_argument
(
'-v'
,
'--version'
,
action
=
"version"
,
version
=
__version__
)
parser
.
add_argument
(
'-H'
,
'--host'
,
default
=
'translate.google.cn'
,
help
=
"host for google translator"
)
parser
.
add_argument
(
'-P'
,
'--proxy'
,
help
=
f
'proxy with format \d+\.\d+\.\d+\.\d+:\d+ or empty'
)
parser
.
add_argument
(
'-t'
,
'--timeout'
,
type
=
float
,
help
=
f
'timeout in second'
)
parser
.
add_argument
(
'-w'
,
'--wait-sec'
,
type
=
float
,
default
=
0.5
,
help
=
'delay in second between two times of translation'
)
parser
.
add_argument
(
'-r'
,
'--retry'
,
type
=
int
,
default
=
10
,
help
=
'count of retrying'
)
parser
.
add_argument
(
'-s'
,
'--src'
,
default
=
'auto'
,
help
=
'src language'
)
...
...
@@ -40,6 +42,7 @@ def main():
args
.
proxy
=
{
'http'
:
p
,
'https'
:
p
}
api
.
host
=
args
.
host
api
.
proxy
=
args
.
proxy
api
.
timeout
=
args
.
timeout
config
.
wait_sec
=
args
.
wait_sec
config
.
retry
=
args
.
retry
config
.
src
=
args
.
src
...
...
BookerTrans/api.py
浏览文件 @
7b53e032
...
...
@@ -16,6 +16,7 @@ class GoTransApi:
self
.
tkk
=
None
self
.
host
=
'translate.google.cn'
self
.
proxy
=
None
self
.
timeout
=
8
@
staticmethod
def
_shr32
(
x
,
bits
):
...
...
@@ -111,7 +112,8 @@ class GoTransApi:
res
=
requests
.
get
(
f
'https://
{
self
.
host
}
/'
,
headers
=
GoTransApi
.
headers
,
proxies
=
self
.
proxy
proxies
=
self
.
proxy
,
timeout
=
self
.
timeout
,
).
text
self
.
tkk
=
re
.
search
(
r
"tkk:'(\d+\.\d+)"
,
res
).
group
(
1
)
return
self
.
tkk
...
...
@@ -125,7 +127,8 @@ class GoTransApi:
res
=
requests
.
get
(
url
,
headers
=
GoTransApi
.
headers
,
proxies
=
self
.
proxy
proxies
=
self
.
proxy
,
timeout
=
self
.
timeout
,
).
text
j
=
json
.
loads
(
res
)
trans
=
' '
.
join
([
o
[
0
]
for
o
in
j
[
0
]])
...
...
README.md
浏览文件 @
7b53e032
...
...
@@ -19,12 +19,13 @@ pip install git+https://github.com/apachecn/BookerTrans
## 使用说明
```
btrans [-h] [-v] [-H HOST] [-P PROXY] [-
w WAIT_SEC] [-r RETRY]
[-s SRC] [-d DST]
btrans [-h] [-v] [-H HOST] [-P PROXY] [-
t TIMEOUT] [-w WAIT_SEC]
[-
r RETRY] [-
s SRC] [-d DST]
fname
-H HOST: 域名,默认为 translate.google.com
-P PROXY: 代理,格式为 \d+\.\d+\.\d+\.\d+:\d+,默认为空
-t TIMEOUT: 超时时间,以秒为单位,默认为 8
-w WAIT_SEC: 两次翻译之间的延迟(以秒为单位),默认为 0.5
-r RETRY: 重试次数,默认为 10
-s SRC: 源语言,默认为 auto
...
...
history.md
0 → 100644
浏览文件 @
7b53e032
# 历史记录
v2020.4.29
+
建立项目
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录