fix #22
This commit is contained in:
parent
a48118331c
commit
50f0615af6
@ -421,10 +421,14 @@ class WebService(Service):
|
|||||||
Downloads a file to the given path from the specified target(s).
|
Downloads a file to the given path from the specified target(s).
|
||||||
See net_stream() for information about available options.
|
See net_stream() for information about available options.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
payload = self.net_stream(*args, **kwargs)
|
payload = self.net_stream(*args, **kwargs)
|
||||||
with open(path, 'wb') as response_output:
|
with open(path, 'wb') as response_output:
|
||||||
response_output.write(payload)
|
response_output.write(payload)
|
||||||
|
response_output.close()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class _DictBuildWorker(QThread):
|
class _DictBuildWorker(QThread):
|
||||||
|
|||||||
@ -76,12 +76,12 @@ class Bing(WebService):
|
|||||||
@export('AME_PHON')
|
@export('AME_PHON')
|
||||||
def fld_phonetic_us(self):
|
def fld_phonetic_us(self):
|
||||||
seg = self._get_field('pronunciation')
|
seg = self._get_field('pronunciation')
|
||||||
return seg.get('AmE', u'')
|
return seg.get('AmE', u'') if seg else u''
|
||||||
|
|
||||||
@export('BRE_PHON')
|
@export('BRE_PHON')
|
||||||
def fld_phonetic_uk(self):
|
def fld_phonetic_uk(self):
|
||||||
seg = self._get_field('pronunciation')
|
seg = self._get_field('pronunciation')
|
||||||
return seg.get('BrE', u'')
|
return seg.get('BrE', u'') if seg else u''
|
||||||
|
|
||||||
def _fld_mp3(self, fld):
|
def _fld_mp3(self, fld):
|
||||||
audio_url = self._get_field('pronunciation')[fld]
|
audio_url = self._get_field('pronunciation')[fld]
|
||||||
|
|||||||
@ -25,9 +25,9 @@ class BingXtk(WebService):
|
|||||||
url = u'http://xtk.azurewebsites.net/BingDictService.aspx?Word={}'.format(word)
|
url = u'http://xtk.azurewebsites.net/BingDictService.aspx?Word={}'.format(word)
|
||||||
try:
|
try:
|
||||||
result.update(json.loads(self.get_response(url, headers=headers, timeout=10)))
|
result.update(json.loads(self.get_response(url, headers=headers, timeout=10)))
|
||||||
return self.cache_this(result)
|
|
||||||
except:
|
except:
|
||||||
return result
|
pass
|
||||||
|
return self.cache_this(result)
|
||||||
|
|
||||||
def _get_field(self, key, default=u''):
|
def _get_field(self, key, default=u''):
|
||||||
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
return self.cache_result(key) if self.cached(key) else self._get_content().get(key, default)
|
||||||
@ -35,12 +35,12 @@ class BingXtk(WebService):
|
|||||||
@export('AME_PHON')
|
@export('AME_PHON')
|
||||||
def fld_phonetic_us(self):
|
def fld_phonetic_us(self):
|
||||||
seg = self._get_field('pronunciation')
|
seg = self._get_field('pronunciation')
|
||||||
return seg.get('AmE', u'')
|
return seg.get('AmE', u'') if seg else u''
|
||||||
|
|
||||||
@export('BRE_PHON')
|
@export('BRE_PHON')
|
||||||
def fld_phonetic_uk(self):
|
def fld_phonetic_uk(self):
|
||||||
seg = self._get_field('pronunciation')
|
seg = self._get_field('pronunciation')
|
||||||
return seg.get('BrE', u'')
|
return seg.get('BrE', u'') if seg else u''
|
||||||
|
|
||||||
def _fld_mp3(self, fld):
|
def _fld_mp3(self, fld):
|
||||||
audio_url = self._get_field('pronunciation')[fld]
|
audio_url = self._get_field('pronunciation')[fld]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user