diff --git a/src/fastwq/service/base.py b/src/fastwq/service/base.py index 30c4adf..b3e524b 100644 --- a/src/fastwq/service/base.py +++ b/src/fastwq/service/base.py @@ -421,10 +421,14 @@ class WebService(Service): Downloads a file to the given path from the specified target(s). See net_stream() for information about available options. """ - - payload = self.net_stream(*args, **kwargs) - with open(path, 'wb') as response_output: - response_output.write(payload) + try: + payload = self.net_stream(*args, **kwargs) + with open(path, 'wb') as response_output: + response_output.write(payload) + response_output.close() + return True + except: + return False class _DictBuildWorker(QThread): diff --git a/src/fastwq/service/dict/bing.py b/src/fastwq/service/dict/bing.py index fcfb209..bbb7b8e 100644 --- a/src/fastwq/service/dict/bing.py +++ b/src/fastwq/service/dict/bing.py @@ -76,12 +76,12 @@ class Bing(WebService): @export('AME_PHON') def fld_phonetic_us(self): seg = self._get_field('pronunciation') - return seg.get('AmE', u'') + return seg.get('AmE', u'') if seg else u'' @export('BRE_PHON') def fld_phonetic_uk(self): seg = self._get_field('pronunciation') - return seg.get('BrE', u'') + return seg.get('BrE', u'') if seg else u'' def _fld_mp3(self, fld): audio_url = self._get_field('pronunciation')[fld] diff --git a/src/fastwq/service/dict/bing3tp.py b/src/fastwq/service/dict/bing3tp.py index a33d6d6..6c544d9 100644 --- a/src/fastwq/service/dict/bing3tp.py +++ b/src/fastwq/service/dict/bing3tp.py @@ -25,9 +25,9 @@ class BingXtk(WebService): url = u'http://xtk.azurewebsites.net/BingDictService.aspx?Word={}'.format(word) try: result.update(json.loads(self.get_response(url, headers=headers, timeout=10))) - return self.cache_this(result) except: - return result + pass + return self.cache_this(result) def _get_field(self, key, default=u''): 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') def fld_phonetic_us(self): seg = self._get_field('pronunciation') - return seg.get('AmE', u'') + return seg.get('AmE', u'') if seg else u'' @export('BRE_PHON') def fld_phonetic_uk(self): seg = self._get_field('pronunciation') - return seg.get('BrE', u'') + return seg.get('BrE', u'') if seg else u'' def _fld_mp3(self, fld): audio_url = self._get_field('pronunciation')[fld]