Merge pull request #114 from JavanZhu/master

Fix bug and improvement
This commit is contained in:
sthoo 2019-01-20 13:44:33 +08:00 committed by GitHub
commit 25146a36ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -60,11 +60,13 @@ class Cambridge(WebService):
for tag in tags: for tag in tags:
i = tag.find('span', class_='def-info') i = tag.find('span', class_='def-info')
d = tag.find('b', class_='def') d = tag.find('b', class_='def')
trans = tag.find('span', class_='trans')
es = tag.find_all('div', class_='examp emphasized') es = tag.find_all('div', class_='examp emphasized')
l.append( l.append(
u'<li>{0}{1}{2}</li>'.format( u'<li>{0}{1}{2}{3}</li>'.format(
u'<span class="epp-xref">{0}</span>'.format(i.get_text()) if i else u'', u'<span class="epp-xref">{0}</span>'.format(i.get_text()) if i else u'',
u'<b class="def">{0}</b>'.format(d.get_text()) if d else u'', u'<b class="def">{0}</b>'.format(d.get_text()) if d else u'',
u'<span class="trans">{0}</span>'.format(trans.get_text()) if trans else u'',
u''.join( u''.join(
u'<div class="examp">{0}</div>'.format(e.get_text()) if e else u'' u'<div class="examp">{0}</div>'.format(e.get_text()) if e else u''
for e in es for e in es

View File

@ -4,6 +4,7 @@ import os
import re import re
from bs4 import Tag from bs4 import Tag
from ..base import * from ..base import *
from ...utils.misc import format_multi_query_word
longman_download_mp3 = True longman_download_mp3 = True
@ -17,7 +18,7 @@ class Longman(WebService):
super(Longman, self).__init__() super(Longman, self).__init__()
def _get_from_api(self): 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) data = self.get_response(url)
soup = parse_html(data) soup = parse_html(data)
# Top Container # Top Container

View File

@ -3,6 +3,7 @@
from bs4 import Tag from bs4 import Tag
from ..base import * from ..base import *
from ...utils.misc import format_multi_query_word
#filterwarnings('ignore') #filterwarnings('ignore')
@ -22,7 +23,7 @@ class OxfordLearning(WebService):
:param word: :param word:
:rtype: WebWord :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 retried = 10
while retried: while retried:
@ -42,6 +43,8 @@ class OxfordLearning(WebService):
self.cache_this( self.cache_this(
{ {
'phonetic': '{} {}'.format(web_word.wd_phon_bre, web_word.wd_phon_nam), '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, 'pos': web_word.wd_pos,
'img_full': web_word.wd_image_full_url, 'img_full': web_word.wd_image_full_url,
'img_thumb': web_word.wd_image_thumb_url, 'img_thumb': web_word.wd_image_thumb_url,
@ -54,6 +57,8 @@ class OxfordLearning(WebService):
self.cache_this( self.cache_this(
{ {
'phonetic': '', 'phonetic': '',
'phon_bre': '',
'phon_ame': '',
'pos': '', 'pos': '',
'img_full': '', 'img_full': '',
'img_thumb': '', 'img_thumb': '',
@ -68,6 +73,14 @@ class OxfordLearning(WebService):
def fld_phonetic(self): def fld_phonetic(self):
return self._get_single_dict('phonetic') 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']) @export([u'词性', u'POS'])
def fld_pos(self): def fld_pos(self):
return self._get_single_dict('pos') return self._get_single_dict('pos')

View File

@ -60,6 +60,16 @@ def get_icon(filename):
return QIcon(path) 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): class MapDict(dict):
""" """
Example: Example: