Add trailing `s' to all Term fields that are a list - 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 0f13f795023fb282957e2f625b677f6b28a148c2
(DIR) parent 82fd2c1517952fea586933602a4e3325daff6f4e
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Tue, 29 Oct 2019 19:18:51
Add trailing `s' to all Term fields that are a list
Diffstat:
wr.py | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
---
diff -r 82fd2c151795 -r 0f13f795023f wr.py
--- a/wr.py Tue Oct 29 19:13:52 2019 +0100
+++ b/wr.py Tue Oct 29 19:18:51 2019 +0100
@@ -50,16 +50,16 @@
'term',
'term_type',
'term_description',
- 'translation',
- 'translation_context',
- 'translation_type',
+ 'translations',
+ 'translation_contexts',
+ 'translation_types',
])
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'
+Term.translations.__doc__ += 'List of all translations'
+Term.translation_contexts.__doc__ += 'List of contexts of all the translations'
+Term.translation_types.__doc__ += 'List of types of all the translations'
def translate(dictionary: str, term: str) -> List[Term]:
@@ -87,9 +87,9 @@
'n'
>>> ts[0].term_description
'(typical instance)'
- >>> ts[0].translation
+ >>> ts[0].translations
'esempio'
- >>> ts[0].translation_type
+ >>> ts[0].translation_types
'nm'
"""
req = request.Request(WORDREFERENCE_URL.format(
@@ -128,22 +128,22 @@
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 not t.get('translation_contexts'):
+ t['translation_contexts'] = []
+ if not t.get('translation_types'):
+ t['translation_types'] = []
if to2:
- t['translation_context'].append(to2.text.strip())
+ t['translation_contexts'].append(to2.text.strip())
else:
- t['translation_context'].append('')
+ t['translation_contexts'].append('')
if pos2 and pos2.children and len(list(pos2.children)) > 0:
- t['translation_type'].append(list(pos2.children)[0].strip())
+ t['translation_types'].append(list(pos2.children)[0].strip())
towrd.find('em', class_='POS2').clear()
else:
- t['translation_type'].append('')
- if not t.get('translation'):
- t['translation'] = []
- t['translation'].append(towrd.text.strip())
+ t['translation_types'].append('')
+ if not t.get('translations'):
+ t['translations'] = []
+ t['translations'].append(towrd.text.strip())
if tr.find('td', class_='FrEx'):
frex = tr.find('td', class_='FrEx')
@@ -163,7 +163,7 @@
print('{term} {term_type}'.format(term=term.term,
term_type=term.term_type))
print('{description}'.format(description=term.term_description))
- for translation, translation_context, translation_type in zip(term.translation, term.translation_context, term.translation_type):
+ for translation, translation_context, translation_type in zip(term.translations, term.translation_contexts, term.translation_types):
if translation_context:
print('{context}'.format(context=translation_context))
print(textwrap.fill('{translation} [{translation_type}]'.format(