mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-04-20 11:01:17 +02:00
fix exceptions
This commit is contained in:
parent
79fbce348b
commit
ff7d566aae
@ -40,5 +40,5 @@ if __name__ == '__main__':
|
|||||||
test.show()
|
test.show()
|
||||||
try:
|
try:
|
||||||
test.download()
|
test.download()
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print 'Exception: %s' % str(e)
|
print 'Exception: %s' % str(e)
|
@ -34,20 +34,20 @@ class Downloader(object):
|
|||||||
else:
|
else:
|
||||||
for chunk in response.iter_content(2048):
|
for chunk in response.iter_content(2048):
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
except (os.error, IOError), e:
|
except requests.HTTPError as e:
|
||||||
if not retried:
|
if not retried:
|
||||||
logger.error('Error: %s, retrying' % str(e))
|
logger.error('Error: %s, retrying' % str(e))
|
||||||
return self._download(url=url, folder=folder, filename=filename, retried=True)
|
return self._download(url=url, folder=folder, filename=filename, retried=True)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.critical('CRITICAL: %s' % str(e))
|
logger.critical('CRITICAL: %s' % str(e))
|
||||||
raise e
|
return None
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def _download_callback(self, request, result):
|
def _download_callback(self, request, result):
|
||||||
if not result:
|
if not result:
|
||||||
logger.critical('Too many network errors occurred, please check your connection.')
|
logger.critical('Too many errors occurred, quit.')
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
logger.log(15, '%s download successfully' % result)
|
logger.log(15, '%s download successfully' % result)
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class Downloader(object):
|
|||||||
logger.warn('Path \'%s\' not exist.' % folder)
|
logger.warn('Path \'%s\' not exist.' % folder)
|
||||||
try:
|
try:
|
||||||
os.mkdir(folder)
|
os.mkdir(folder)
|
||||||
except os.error, e:
|
except EnvironmentError as e:
|
||||||
logger.critical('Error: %s' % str(e))
|
logger.critical('Error: %s' % str(e))
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
else:
|
else:
|
||||||
|
@ -75,7 +75,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
if fd is not None:
|
if fd is not None:
|
||||||
fd = fd()
|
fd = fd()
|
||||||
|
|
||||||
if fd in (1, 2): # stdout or stderr
|
if fd in (1, 2): # stdout or stderr
|
||||||
h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)
|
h = ctypes.windll.kernel32.GetStdHandle(-10 - fd)
|
||||||
|
|
||||||
while parts:
|
while parts:
|
||||||
@ -97,11 +97,11 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
elif 30 <= p <= 37:
|
elif 30 <= p <= 37:
|
||||||
color |= self.nt_color_map[p - 30]
|
color |= self.nt_color_map[p - 30]
|
||||||
elif p == 1:
|
elif p == 1:
|
||||||
color |= 0x08 # foreground intensity on
|
color |= 0x08 # foreground intensity on
|
||||||
elif p == 0: # reset to default color
|
elif p == 0: # reset to default color
|
||||||
color = 0x07
|
color = 0x07
|
||||||
else:
|
else:
|
||||||
pass # error condition ignored
|
pass # error condition ignored
|
||||||
|
|
||||||
ctypes.windll.kernel32.SetConsoleTextAttribute(h, color)
|
ctypes.windll.kernel32.SetConsoleTextAttribute(h, color)
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class ColorizingStreamHandler(logging.StreamHandler):
|
|||||||
prefix = ""
|
prefix = ""
|
||||||
|
|
||||||
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params),
|
message = "%s%s" % (prefix, ''.join((self.csi, ';'.join(params),
|
||||||
'm', message, self.reset)))
|
'm', message, self.reset)))
|
||||||
|
|
||||||
return message
|
return message
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ def dojinshi_parser(id):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url).content
|
response = requests.get(url).content
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
logger.critical('%s%s' % tuple(e.message))
|
logger.critical('%s%s' % tuple(e.message))
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user