def process(names, args, times=1): global print_err, print_log, print_bold raised = False start_time = time.time() if args.nocolors: print_err = print_log = print_bold = print try: link_count = -1 for s in names: if s == args.end: print_bold(s) else: print(s) link_count += 1 except ConnectionError: print_err('Network error, please check your connection') sys.exit(1) except MediaWikiError as e: print_err('Error: {}: {}'.format( e.errors['code'], e.errors['info'])) raised = True except LoopException as e: print_log('---\n{}, quitting...'.format(e)) print_log('Visited {} link(s), got a loop, taking {} seconds'.format( link_count, round(time.time() - start_time, 4))) raised = True except InvalidPageNameError as e: print_err(e) raised = True except LinkNotFoundError as e: print_err(e) print_log('---') print_log(('Visited {} link(s), could not find appropriate link' + ' in last link, taking {} seconds').format( link_count, round(time.time() - start_time, 4))) raised = True if not raised: print_log('---') print_log('Took {} hop(s) and {} seconds'.format( link_count, round(time.time() - start_time, 4))) if times == args.times: return # New line for separation print('') names = philosophy.trace(end=args.end, infinite=args.infinite) process(names, args, times=times+1)
def main(): args = getargs() args.start = ' '.join(args.start) args.end = ' '.join(args.end) if args.start == '': args.start = None if args.end == '': args.end = 'Philosophy' names = philosophy.trace(page=args.start, end=args.end, infinite=args.infinite) process(names, args)