red on black terminal better bold to easier view

This commit is contained in:
limkokhole
2020-06-24 17:12:39 +08:00
parent 9a59ed5b6b
commit d7073c7b3c

View File

@@ -100,7 +100,7 @@ def quit(msgs, exit=True):
if msg == '\n': if msg == '\n':
print('\n') print('\n')
else: else:
cprint(''.join([ HIGHER_RED, '%s' % (msg) ]), end='\n' ) cprint(''.join([ HIGHER_RED, '%s' % (msg) ]), attrs=BOLD_ONLY, end='\n' )
# https://stackoverflow.com/a/34325723/1074998 # https://stackoverflow.com/a/34325723/1074998
@@ -337,7 +337,7 @@ def fetch_boards(uname):
boards.extend(data['resource_response']['data']) boards.extend(data['resource_response']['data'])
bookmark = data['resource']['options']['bookmarks'][0] bookmark = data['resource']['options']['bookmarks'][0]
except TypeError: # Normal if invalid username except TypeError: # Normal if invalid username
cprint(''.join([ HIGHER_RED, '%s' % ('\n[' + x_tag + '] Possible invalid username.\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\n[' + x_tag + '] Possible invalid username.\n\n') ]), attrs=BOLD_ONLY, end='' )
break break
b_len = len(boards) b_len = len(boards)
print('[' + plus_tag + '] Found {} Board{}.'.format(b_len, 's' if b_len > 1 else '')) print('[' + plus_tag + '] Found {} Board{}.'.format(b_len, 's' if b_len > 1 else ''))
@@ -454,8 +454,8 @@ def download_img(image, save_dir, arg_force_update, IMG_SESSION, V_SESSION, arg_
pass pass
except OSError: # e.g. File name too long except OSError: # e.g. File name too long
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at'
, file_path, 'failed :', url, '\n') ]), end='' ) , file_path, 'failed :', url, '\n') ]), attrs=BOLD_ONLY, end='' )
cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc()) return quit(traceback.format_exc())
if not os.path.exists(file_path) or arg_force_update: if not os.path.exists(file_path) or arg_force_update:
@@ -475,13 +475,13 @@ def download_img(image, save_dir, arg_force_update, IMG_SESSION, V_SESSION, arg_
except OSError: # e.g. File name too long except OSError: # e.g. File name too long
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at'
, file_path, 'failed :', url, '\n') ]), end='' ) , file_path, 'failed :', url, '\n') ]), attrs=BOLD_ONLY, end='' )
cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc()) return quit(traceback.format_exc())
else: else:
#cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at' #cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this image at'
#, file_path, 'failed :', url, '\n') ]), end='' ) #, file_path, 'failed :', url, '\n') ]), attrs=BOLD_ONLY, end='' )
imgDimens = [] imgDimens = []
imgDimensD = {} imgDimensD = {}
for ik, iv in image['images'].items(): for ik, iv in image['images'].items():
@@ -506,8 +506,8 @@ def download_img(image, save_dir, arg_force_update, IMG_SESSION, V_SESSION, arg_
f.write(chunk) f.write(chunk)
except OSError: # e.g. File name too long except OSError: # e.g. File name too long
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Retried this image at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Retried this image at'
, file_path, 'failed :', url, '\n') ]), end='' ) , file_path, 'failed :', url, '\n') ]), attrs=BOLD_ONLY, end='' )
cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc()) return quit(traceback.format_exc())
#print('\n\n[' + plus_tag + '] ', end='') # konsole has issue if BOLD_ONLY with cprint with plus_tag #print('\n\n[' + plus_tag + '] ', end='') # konsole has issue if BOLD_ONLY with cprint with plus_tag
@@ -516,7 +516,7 @@ def download_img(image, save_dir, arg_force_update, IMG_SESSION, V_SESSION, arg_
#cprint('\nRetried with second best quality url success :D {} saved to {}\n'.format(url, file_path), attrs=BOLD_ONLY) #cprint('\nRetried with second best quality url success :D {} saved to {}\n'.format(url, file_path), attrs=BOLD_ONLY)
else: else:
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Retried this image at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Retried this image at'
, file_path, 'failed :', url, '\n') ]), end='' ) , file_path, 'failed :', url, '\n') ]), attrs=BOLD_ONLY, end='' )
else: else:
pass #cprint('\nFile at {} already exist.\n'.format(file_path), attrs=BOLD_ONLY) pass #cprint('\nFile at {} already exist.\n'.format(file_path), attrs=BOLD_ONLY)
@@ -556,13 +556,13 @@ def download_img(image, save_dir, arg_force_update, IMG_SESSION, V_SESSION, arg_
f.write(chunk) f.write(chunk)
except OSError: # e.g. File name still too long except OSError: # e.g. File name still too long
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this video at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this video at'
, save_dir, 'failed :', vurl, '\n') ]), end='' ) , save_dir, 'failed :', vurl, '\n') ]), attrs=BOLD_ONLY, end='' )
cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc()) return quit(traceback.format_exc())
else: else:
cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this video at' cprint(''.join([ HIGHER_RED, '%s %s %s %s%s' % ('\n[' + x_tag + '] Download this video at'
, save_dir, 'failed :', vurl, '\n') ]), end='' ) , save_dir, 'failed :', vurl, '\n') ]), attrs=BOLD_ONLY, end='' )
except: # Need catch inside job, or else it doesn't throws except: # Need catch inside job, or else it doesn't throws
print() print()
@@ -588,7 +588,7 @@ def create_dir(save_dir):
# So you direct throws OSError enough to remind that user don't make insane fs hier # So you direct throws OSError enough to remind that user don't make insane fs hier
cprint(''.join([ HIGHER_RED, '%s' % ('\nIt might causes by too long(2045 bytes) in full path.\ cprint(''.join([ HIGHER_RED, '%s' % ('\nIt might causes by too long(2045 bytes) in full path.\
You may want to to use -d <other path> OR -c <Maximum length of filename>.\n\n') ]), end='' ) You may want to to use -d <other path> OR -c <Maximum length of filename>.\n\n') ]), attrs=BOLD_ONLY, end='' )
raise raise
def write_log(arg_timestamp_log, save_dir, images, pin): def write_log(arg_timestamp_log, save_dir, images, pin):
@@ -642,7 +642,7 @@ def write_log(arg_timestamp_log, save_dir, images, pin):
f.write('[ ' + str(log_i + 1 - skipped_total) + ' ] Pin Id: ' + str(image_id) + '\n') f.write('[ ' + str(log_i + 1 - skipped_total) + ' ] Pin Id: ' + str(image_id) + '\n')
f.write(story + '\n\n') f.write(story + '\n\n')
except OSError: # e.g. File name too long except OSError: # e.g. File name too long
cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s' % ('\nYou may want to use -c <Maximum length of filename>\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc()) return quit(traceback.format_exc())
else: else:
skipped_total+=1 skipped_total+=1
@@ -691,7 +691,7 @@ def fetch_imgs(board, uname, board_name, section, arg_timestamp, arg_timestamp_l
Please ensure your username/boardname or link has media item.\n') ) Please ensure your username/boardname or link has media item.\n') )
except (KeyError, TypeError): except (KeyError, TypeError):
url = '/'.join((uname, board_name)) url = '/'.join((uname, board_name))
cprint(''.join([ HIGHER_RED, '%s %s %s' % ('\n[' + x_tag + '] Failed. URL:', url, '\n\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '%s %s %s' % ('\n[' + x_tag + '] Failed. URL:', url, '\n\n') ]), attrs=BOLD_ONLY, end='' )
return quit(traceback.format_exc() + '\n[!] Something wrong with Pinterest URL. Please report this issue at https://github.com/limkokhole/pinterest-downloader/issues , thanks.') return quit(traceback.format_exc() + '\n[!] Something wrong with Pinterest URL. Please report this issue at https://github.com/limkokhole/pinterest-downloader/issues , thanks.')
if section: if section:
@@ -1007,10 +1007,10 @@ if __name__ == '__main__':
try: try:
main() main()
except requests.exceptions.ReadTimeout: except requests.exceptions.ReadTimeout:
cprint(''.join([ HIGHER_RED, '{}'.format('\n[' + x_tag + '] Suddenly not able to connect. Please check your network.\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '{}'.format('\n[' + x_tag + '] Suddenly not able to connect. Please check your network.\n') ]), attrs=BOLD_ONLY, end='' )
quit('') quit('')
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
cprint(''.join([ HIGHER_RED, '{}'.format('\n[' + x_tag + '] Not able to connect. Please check your network.\n') ]), end='' ) cprint(''.join([ HIGHER_RED, '{}'.format('\n[' + x_tag + '] Not able to connect. Please check your network.\n') ]), attrs=BOLD_ONLY, end='' )
quit('') quit('')
except: except:
quit(traceback.format_exc()) quit(traceback.format_exc())