rbaron / dict.cc.py Goto Github PK
View Code? Open in Web Editor NEW📘 Unofficial command line client for dict.cc
📘 Unofficial command line client for dict.cc
That is a nice script - thanks for that!
I installed it via pip and wanted to test it on my windows machine by just call "dict.cc.py" in console window.
It throws the following error:
C:\Whatever>dict.cc.py
File "C:\...\python_3.5.0\Scripts\dict.cc.py", line 31
print "{}{}{}\n{}{}{}".format(
^
SyntaxError: invalid syntax
So I checked line 31 of the dict.cc.py-file in my Scripts folder and got confused because of the difference between this line and the one which is online here on github:
Installed via pip: print "{}{}{}\n{}{}{}".format(
Github (line 32): print(u"{}{}{}\n{}{}{}".format(
Is the pip package not up2date?
It would be great if we could avoid having to type the source and target language all the time. Instead of doing:
$ dict.cc.py en de body
We could let users configure which languages they would like to be the default, so they could avoid having to type en de
all the time (although they can type it if they want non-default options):
$ dict.cc.py body
Two ideas for handling this config:
~/.dict.cc.py.yaml
)DICT_CC_PY_LANGS="en de"
)I tend to favor the first approach, but at this complexity level it's a matter of personal taste 🙂
The way the HTML is parsed is very hacky and very fragile to changes in the results page. I think we would benefit from a more robust strategy for looking for the relevant tags.
The parsing is currently done here.
Installed from pip and it is up to date.
dict.cc.py de en test
results in
Traceback (most recent call last):
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/connectionpool.py", line 594, in urlopen
self._prepare_proxy(conn)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
conn.connect()
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/connection.py", line 344, in connect
ssl_context=context)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 344, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/usr/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/urllib3/util/retry.py", line 398, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='deen.dict.cc', port=443): Max retries exceeded with url: /?s=test (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tlothpa/venv/dictcc/bin/dict.cc.py", line 82, in <module>
run()
File "/home/tlothpa/venv/dictcc/bin/dict.cc.py", line 63, in run
args.output_language)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/dictcc/dictcc.py", line 51, in translate
response_body = cls._get_response(word, from_language, to_language)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/dictcc/dictcc.py", line 61, in _get_response
headers={'User-agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0'}
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='deen.dict.cc', port=443): Max retries exceeded with url: /?s=test (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)'),))
This is the command line and exception:
dict.cc.py de en körper
Showing 20 of 49 result(s)
Englisch Deutsch
======== ========
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/dict.cc/dict.cc.py", line 129, in <module>
run()
File "/usr/lib/python3.6/site-packages/dict.cc/dict.cc.py", line 123, in run
print_translation(input_word, output_word, args.color, args.word)
File "/usr/lib/python3.6/site-packages/dict.cc/dict.cc.py", line 99, in print_translation
print(u"{} {} = {}".format(apply_color(input_word),
File "/usr/lib/python3.6/site-packages/dict.cc/dict.cc.py", line 90, in apply_color
string = re.sub(r"\b({})\b".format(re.escape(wrd)),
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 2: ordinal not in range(128)
Commenting out loop beginning in scripts/dict.cc.py:89
solves the issue ...
Env: Python 2.7.17 and Python 3.8.0
See below.
% dict.cc.py en de verfügbar
Traceback (most recent call last):
File "/usr/bin/dict.cc.py", line 73, in <module>
run()
File "/usr/bin/dict.cc.py", line 54, in run
args.output_language)
File "/usr/lib/python3.5/site-packages/dictcc/dictcc.py", line 57, in translate
response_body = cls._get_response(word, from_language, to_language)
File "/usr/lib/python3.5/site-packages/dictcc/dictcc.py", line 73, in _get_response
res = urllib2.urlopen(req).read()
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)
File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
'_open', req)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.5/http/client.py", line 1106, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1141, in _send_request
self.putrequest(method, url, **skips)
File "/usr/lib/python3.5/http/client.py", line 983, in putrequest
self._output(request.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 12: ordinal not in range(128)
Am I the only one? Since today it raises the following error:
Traceback (most recent call last):
File "/home/tlothpa/venv/dictcc/bin/dict.cc.py", line 81, in <module>
run()
File "/home/tlothpa/venv/dictcc/bin/dict.cc.py", line 62, in run
args.output_language)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/dictcc/dictcc.py", line 59, in translate
response_body = cls._get_response(word, from_language, to_language)
File "/home/tlothpa/venv/dictcc/lib/python3.6/site-packages/dictcc/dictcc.py", line 76, in _get_response
res = urllib2.urlopen(req).read()
File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
Hi @rbaron
I tried to get this to run on OS X, but without any success ("pip" not available). Can you explain in more detail, what is required and how to setup the application to run this on OS X (I think it's most likely very similiar to Linux anyway)?
Additionally, I feel like one needs to obtain some file(s) from dict.cc - like the translation database(s) - additionally to the application itself. Can this be? If yes, where and which files do I need?
Thanks & best regards,
Oliver
Error:
dict.cc.py:89: SyntaxWarning: invalid escape sequence '\w' for wrd in re.sub('[^\w] ', '', search_phrase).split(" "):
Fix:
Use raw string expression:
re.sub(r'[^\w] ', '', search_phrase).split(" "):
today i realized that i only get a maximum of 3 results anymore. anyone an idea of how to fix this?
here the message:
limited result set
more at www.dict.cc
in your web browser
Would be great if the documentation would also include the usage as code not just command line. Is it intended to be used apart from command line?
There's one quite useful feature of the web interface that would be nice to have in this tool: Suggestions. For example, when I search for apathic
, it suggests pathic
.
I would like to store the result in a variable before doing fourther procseeing like this:
TRANSLATION=$(dict.cc.py en de hello)
When I execute this then I get a python error:
Traceback (most recent call last):
File "/usr/local/bin/dict.cc.py", line 73, in <module>
run()
File "/usr/local/bin/dict.cc.py", line 67, in run
print_translation(input_word, output_word)
File "/usr/local/bin/dict.cc.py", line 45, in print_translation
output_word))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 62: ordinal not in range(128)
Hi,
I really like your work! I get the following warning on my environment, I have python 2.7 and python 3.5 installed but using python 2.7 for the translations scripts:
% /usr/lib/python2.7/site-packages/dict.cc/dict.cc.py en de test
/usr/lib/python2.7/site-packages/bs4/__init__.py:166: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
To get rid of this warning, change this:
BeautifulSoup([your markup])
to this:
BeautifulSoup([your markup], "html.parser")
markup_type=markup_type))
Showing 10 of 49 result(s)
Englisch Deutsch
======== =======
to test.....................................................testen
to test sth.................................................etw. prüfen
to test.....................................................ausprobieren
to test.....................................................untersuchen
to test.....................................................austesten
to test.....................................................erproben
to test sth.................................................etw. probieren
to test.....................................................kontrollieren
to test sb..................................................jdn. auf die Probe stellen
to test sth.................................................etw. überprüfen
to trial....................................................einem Test unterziehen
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.