From 9c4771fdf980032e9d097a2afccd24bfa1053b27 Mon Sep 17 00:00:00 2001 From: Javan Zhu Date: Sun, 20 Jan 2019 09:34:04 +0800 Subject: [PATCH 1/3] Add AME_PHON and BRE_PHON fields to oxford_learning dictionary export. --- addons21/fastwq/service/dict/oxford_learning.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons21/fastwq/service/dict/oxford_learning.py b/addons21/fastwq/service/dict/oxford_learning.py index 88c1b6d..0068aab 100644 --- a/addons21/fastwq/service/dict/oxford_learning.py +++ b/addons21/fastwq/service/dict/oxford_learning.py @@ -42,6 +42,8 @@ class OxfordLearning(WebService): self.cache_this( { 'phonetic': '{} {}'.format(web_word.wd_phon_bre, web_word.wd_phon_nam), + 'phon_bre': '{}'.format(web_word.wd_phon_bre), + 'phon_ame': '{}'.format(web_word.wd_phon_nam), 'pos': web_word.wd_pos, 'img_full': web_word.wd_image_full_url, 'img_thumb': web_word.wd_image_thumb_url, @@ -54,6 +56,8 @@ class OxfordLearning(WebService): self.cache_this( { 'phonetic': '', + 'phon_bre': '', + 'phon_ame': '', 'pos': '', 'img_full': '', 'img_thumb': '', @@ -68,6 +72,14 @@ class OxfordLearning(WebService): def fld_phonetic(self): return self._get_single_dict('phonetic') + @export('AME_PHON') + def fld_phonetic_us(self): + return self._get_single_dict('phon_ame') + + @export('BRE_PHON') + def fld_phonetic_uk(self): + return self._get_single_dict('phon_bre') + @export([u'词性', u'POS']) def fld_pos(self): return self._get_single_dict('pos') From bb487e1259c9b8caf70a2505d22ef90d38a0ace5 Mon Sep 17 00:00:00 2001 From: Javan Zhu Date: Sun, 20 Jan 2019 09:44:22 +0800 Subject: [PATCH 2/3] Fix bug that can not query word like 'Saudi Arabia' by longman and oxford learning --- addons21/fastwq/service/dict/longman.py | 3 ++- addons21/fastwq/service/dict/oxford_learning.py | 3 ++- addons21/fastwq/utils/misc.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons21/fastwq/service/dict/longman.py b/addons21/fastwq/service/dict/longman.py index fc40a2d..511b737 100644 --- a/addons21/fastwq/service/dict/longman.py +++ b/addons21/fastwq/service/dict/longman.py @@ -4,6 +4,7 @@ import os import re from bs4 import Tag from ..base import * +from ...utils.misc import format_multi_query_word longman_download_mp3 = True @@ -17,7 +18,7 @@ class Longman(WebService): super(Longman, self).__init__() def _get_from_api(self): - url = 'https://www.ldoceonline.com/dictionary/{}'.format(self.quote_word) + url = 'https://www.ldoceonline.com/dictionary/{}'.format(format_multi_query_word(self.quote_word)) data = self.get_response(url) soup = parse_html(data) # Top Container diff --git a/addons21/fastwq/service/dict/oxford_learning.py b/addons21/fastwq/service/dict/oxford_learning.py index 0068aab..321105b 100644 --- a/addons21/fastwq/service/dict/oxford_learning.py +++ b/addons21/fastwq/service/dict/oxford_learning.py @@ -3,6 +3,7 @@ from bs4 import Tag from ..base import * +from ...utils.misc import format_multi_query_word #filterwarnings('ignore') @@ -22,7 +23,7 @@ class OxfordLearning(WebService): :param word: :rtype: WebWord """ - qry_url = u'https://www.oxfordlearnersdictionaries.com/definition/english/{}'.format(word) + qry_url = u'https://www.oxfordlearnersdictionaries.com/definition/english/{}'.format(format_multi_query_word(word)) retried = 10 while retried: diff --git a/addons21/fastwq/utils/misc.py b/addons21/fastwq/utils/misc.py index f9df336..e76859c 100644 --- a/addons21/fastwq/utils/misc.py +++ b/addons21/fastwq/utils/misc.py @@ -60,6 +60,16 @@ def get_icon(filename): return QIcon(path) +# Some query words like 'Saudi Arabia' is comprised by two or more words that split by '%20'(space), +# it is an invalid query format. (Validated Dictionary: Longman, oxford learning) +def format_multi_query_word(words: str): + _space = '%20' + if words is None or _space not in words: + return words + + return words.lower().replace(_space, '-') + + class MapDict(dict): """ Example: From 4047a5a16998ac08e828ed054859864f6d66cd68 Mon Sep 17 00:00:00 2001 From: Javan Zhu Date: Sun, 20 Jan 2019 09:46:42 +0800 Subject: [PATCH 3/3] Add simplified and traditional translation fields to cambridge dictionary. --- addons21/fastwq/service/dict/cambridge.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons21/fastwq/service/dict/cambridge.py b/addons21/fastwq/service/dict/cambridge.py index 78c8b68..4a1a38d 100644 --- a/addons21/fastwq/service/dict/cambridge.py +++ b/addons21/fastwq/service/dict/cambridge.py @@ -60,11 +60,13 @@ class Cambridge(WebService): for tag in tags: i = tag.find('span', class_='def-info') d = tag.find('b', class_='def') + trans = tag.find('span', class_='trans') es = tag.find_all('div', class_='examp emphasized') l.append( - u'
  • {0}{1}{2}
  • '.format( + u'
  • {0}{1}{2}{3}
  • '.format( u'{0}'.format(i.get_text()) if i else u'', u'{0}'.format(d.get_text()) if d else u'', + u'{0}'.format(trans.get_text()) if trans else u'', u''.join( u'
    {0}
    '.format(e.get_text()) if e else u'' for e in es