def run(self): """Method for thread loop.""" migrate_data() # See if archive folder [already exists for out_dir in (OUTPUT_DIR, 'bookmarks', 'pocket', 'pinboard', 'html'): if os.path.exists(out_dir): break else: out_dir = OUTPUT_DIR resume = None # Continue looping until stopped while not self.stop: link = ArchiveQueue.get_link() if link is None: # If no link is returned, the queue is empty, so # wait and iterate again sleep(5) continue try: print('Processing %s' % link) source = save_stdin_source(link) # Step 1: Parse the links and dedupe them with existing archive all_links, new_links = load_links(archive_path=out_dir, import_path=source) # Step 2: Write new index write_links_index(out_dir=out_dir, links=all_links) # Step 3: Run the archive methods for each link if ONLY_NEW: update_archive(out_dir, new_links, source=source, resume=resume, append=True) else: update_archive(out_dir, all_links, source=source, resume=resume, append=True) # Step 4: Re-write links index with # updated titles, icons, and resources all_links, _ = load_links(archive_path=out_dir) write_links_index(out_dir=out_dir, links=all_links) print('Processing complete: %s' % link) except Exception as exc: print('Exception thrown whilst processing: %s' % str(exc))
)) print(' - {} entries skipped'.format(_RESULTS_TOTALS['skipped'])) print(' - {} entries updated'.format(_RESULTS_TOTALS['succeded'])) print(' - {} errors'.format(_RESULTS_TOTALS['failed'])) print(' To view your archive, open: {}/index.html'.format( OUTPUT_DIR.replace(REPO_DIR + '/', ''))) if __name__ == '__main__': argc = len(sys.argv) if set(sys.argv).intersection(('-h', '--help', 'help')): print_help() raise SystemExit(0) migrate_data() source = sys.argv[1] if argc > 1 else None # path of links file to import resume = sys.argv[ 2] if argc > 2 else None # timestamp to resume dowloading from stdin_raw_text = [] if not sys.stdin.isatty(): stdin_raw_text = sys.stdin.read() if source and stdin_raw_text: print('[X] You should pass either a path as an argument, ' 'or pass a list of links via stdin, but not both.\n') print_help() raise SystemExit(1)