Fix bug that can not query word like 'Saudi Arabia' by longman and oxford learning
This commit is contained in:
parent
9c4771fdf9
commit
bb487e1259
@ -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
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user