Add translation_context to Term - wr - Translate a term via WordReference.com
(HTM) hg clone https://bitbucket.org/iamleot/wr
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset 82fd2c1517952fea586933602a4e3325daff6f4e
(DIR) parent e4cab39042e06f9158917c9eeeeae77ecee0d901
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Tue, 29 Oct 2019 19:13:52
Add translation_context to Term
Some terms (e.g. `mull') also have a `To2' <td> that contains a sort of
"context" for the translation.
Thanks to Rocky Hotas for spotting and investigating that!
Diffstat:
wr.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
---
diff -r e4cab39042e0 -r 82fd2c151795 wr.py
--- a/wr.py Tue Oct 29 15:16:42 2019 +0100
+++ b/wr.py Tue Oct 29 19:13:52 2019 +0100
@@ -51,12 +51,14 @@
'term_type',
'term_description',
'translation',
+ 'translation_context',
'translation_type',
])
Term.term.__doc__ += 'Term'
Term.term_description.__doc__ += 'Description of the term'
Term.term_type.__doc__ += 'Type of the term'
Term.translation.__doc__ += 'List of all translations'
+Term.translation_context.__doc__ += 'List of contexts of all the translations'
Term.translation_type.__doc__ += 'List of types of all the translations'
@@ -125,8 +127,15 @@
if tr.find('td', class_='ToWrd'):
towrd = tr.find('td', class_='ToWrd')
pos2 = towrd.find('em', class_='POS2')
+ to2 = tr.find('td', class_='To2')
+ if not t.get('translation_context'):
+ t['translation_context'] = []
if not t.get('translation_type'):
t['translation_type'] = []
+ if to2:
+ t['translation_context'].append(to2.text.strip())
+ else:
+ t['translation_context'].append('')
if pos2 and pos2.children and len(list(pos2.children)) > 0:
t['translation_type'].append(list(pos2.children)[0].strip())
towrd.find('em', class_='POS2').clear()
@@ -154,7 +163,9 @@
print('{term} {term_type}'.format(term=term.term,
term_type=term.term_type))
print('{description}'.format(description=term.term_description))
- for translation, translation_type in zip(term.translation, term.translation_type):
+ for translation, translation_context, translation_type in zip(term.translation, term.translation_context, term.translation_type):
+ if translation_context:
+ print('{context}'.format(context=translation_context))
print(textwrap.fill('{translation} [{translation_type}]'.format(
translation=translation,
translation_type=translation_type),