Skip to main content

baidu translate for free

Project description

baidu-tr-free Python3.6 packagePyPI version

Baidu translate for free -- local cache plus throttling. Let's hope it lasts.

Broken or not

Python3.6 package: 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_rw or pip 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.git or download https://github.com/ffreemt/baidu-tr-free/archive/master.zip and unzip) and change to the baidu-tr-free folder and do a python 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

baidu-tr-free-0.0.9.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

baidu_tr_free-0.0.9-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file baidu-tr-free-0.0.9.tar.gz.

File metadata

  • Download URL: baidu-tr-free-0.0.9.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for baidu-tr-free-0.0.9.tar.gz
Algorithm Hash digest
SHA256 aa83a5ad9f33a9925bae55145236bb975a83db76fc965bbc3ed9149cd517bd8a
MD5 5c15a97399852c6f69db53ba66c1784e
BLAKE2b-256 f2f53d8c7c661156ebac2945c11df100d359bbda29a0187d9f3b7aeda76acb0f

See more details on using hashes here.

File details

Details for the file baidu_tr_free-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: baidu_tr_free-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for baidu_tr_free-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 18bdf80e0134e022d66db136ce5bc17a479ffe0baa9a877c85305999e748ff6b
MD5 91ae9137767d2661c52e4fd0bd59ef7f
BLAKE2b-256 137488b19544df8d4886f065d5653207f5a889e42eb8dca027ee92e2e8a540a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page