baidu-tr-free 


Baidu translate for free -- local cache plus throttling. Let's hope it lasts.
Broken or not
: failing indicates
broken. In case of failing, try the following workaround: log in to https://passport.baidu.com first. Then use the Chrome browser to visit https://fanyi.baidu.com/v2transapi?from=en&to=zh&query=test, press F12 and then ctr-R (or any method) to open devtools' Network tab and reload. Locate https://fanyi.baidu.com/v2transapi?from=en&to=zh and obtain the BAIDUID and token strings in the headers. Plug in the BAIDUID and token strings to lines 66-67 in the file bdtr.py.
Fixed
- Text longer than 30 characters can be handled now.
- Auto-fetching BAIDUID and TOKEN
Installation
pip install -U baidu-tr-free
or
- install (pip or whatever) necessary requirements, e.g.
pip install js2py requests_cache jsonpath_rworpip install -r requirements.txt - Drop the file bdtr.py in any folder in your PYTHONPATH (check with import sys; print(sys.path)
- Several valid TOKEN/BAIDUID are included.
- or clone the repo (e.g.,
git clone https://github.com/ffreemt/baidu-tr-free.gitor download https://github.com/ffreemt/baidu-tr-free/archive/master.zip and unzip) and change to the baidu-tr-free folder and do apython setup.py develop
Usage
Log in to https://passport.baidu.com using Chrome: bdtr needs the cookies info (BAIDUID) from the Chrome browser on baidu.com.
from bdtr import bdtr
print(bdtr('hello world')) # -> '你好,世界'
print(bdtr('hello world', to_lang='de')) # ->'Hallo Welt'
print(bdtr('hello world', to_lang='jp')) # ->'ハローワールド'
to_lang='fr' does not seem to work tho.
Validation and Pressure Tests
- pip install pytest
- pytest
- Average delay for throttling set to 0.6 s, ajdust as needed
Acknowledgments
- Thanks to everyone whose code was used
- JS_SIGN (javascript code for signing) can be found on the net. It's also not too difficult to obtain some similar code from Chrome's devtools.
Metadata
Release files for baidu-tr-free 0.0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| baidu-tr-free-0.0.10.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| baidu_tr_free-0.0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / baidu-tr-free-0.0.10.tar.gz
| Download URL | baidu-tr-free-0.0.10.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8934c0fce958f0475e4b6830e78defdc9177b5c90bbf391d587082849d79b7da
|
|
BLAKE2b-256 checksum How to use checksums |
88176a1a2545472480a48cdbdf169a7ce46b2df734935b36a2674b00af0cfad6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
|
Release files / baidu_tr_free-0.0.10-py3-none-any.whl
| Download URL | baidu_tr_free-0.0.10-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd230ec341d95023d8573dff2c2da0c0a479c8defd27f42ba326ce84b456abca
|
|
BLAKE2b-256 checksum How to use checksums |
8ad01e4d76067e1a09fc19bf65fc62c7254458856e01146fa809f8ab0bc6aa50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.10
|