|
1 | | -from .corpus.plos_corpus import main |
| 1 | +import os |
| 2 | + |
| 3 | +from . import get_corpus_dir, newarticledir, uncorrected_proofs_text_list |
| 4 | +from .corpus.plos_corpus import (create_local_plos_corpus, get_dois_needed_list, download_check_and_move, |
| 5 | + min_files_for_valid_corpus) |
| 6 | + |
| 7 | + |
| 8 | +def main(): |
| 9 | + """ |
| 10 | + Entry point for the program. This is used when the program is used as a |
| 11 | + standalone script |
| 12 | + :return: None |
| 13 | + """ |
| 14 | + directory = get_corpus_dir() |
| 15 | + |
| 16 | + # Step 0: Initialize first copy of repository |
| 17 | + try: |
| 18 | + corpus_files = [name for name in os.listdir(directory) if os.path.isfile( |
| 19 | + os.path.join(directory, name))] |
| 20 | + except FileNotFoundError: |
| 21 | + corpus_files = [] |
| 22 | + if len(corpus_files) < min_files_for_valid_corpus: |
| 23 | + print('Not enough articles in {}, re-downloading zip file'.format(directory)) |
| 24 | + # TODO: check if zip file is in top-level directory before downloading |
| 25 | + create_local_plos_corpus() |
| 26 | + |
| 27 | + # Step 1: Query solr via URL and construct DOI list |
| 28 | + # Filtered by article type & scheduled for the last 14 days. |
| 29 | + # Returns specific URL query & the number of search results. |
| 30 | + # Parses the returned dictionary of article DOIs, removing common leading numbers, as a list. |
| 31 | + # Compares to list of existing articles in the PLOS corpus folder to create list of DOIs to download. |
| 32 | + print("Checking for new articles...") |
| 33 | + dois_needed_list = get_dois_needed_list() |
| 34 | + |
| 35 | + # Step 2: Download new articles |
| 36 | + # For every doi in dois_needed_list, grab the accompanying XML from journal pages |
| 37 | + # If no new articles, don't run any other cells |
| 38 | + # Check if articles are uncorrected proofs |
| 39 | + # Check if amended articles linked to new amendment articles are updated |
| 40 | + # Merge new XML into folder |
| 41 | + # If need to bulk download, please start here: |
| 42 | + # https://drive.google.com/open?id=0B_JDnoghFeEKLTlJT09IckMwOFk |
| 43 | + download_check_and_move(dois_needed_list, |
| 44 | + uncorrected_proofs_text_list, |
| 45 | + tempdir=newarticledir, |
| 46 | + destination=get_corpus_dir() |
| 47 | + ) |
| 48 | + return None |
| 49 | + |
2 | 50 |
|
3 | 51 | if __name__ == "__main__": |
4 | 52 | main() |
0 commit comments