-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add script to download latest papers from BioRxiv and MedRxiv s…
…ervers
- Loading branch information
Showing
8 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/data/rxivx/biorxiv/downloaded/biorxiv_2024-02-10_2024-02-08.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"doi": "10.1101/12345678" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"doi": "10.1101/12345678" | ||
} | ||
] |
5 changes: 5 additions & 0 deletions
5
src/data/rxivx/medrxiv/downloaded/medrxiv_2024-01-01_2024-02-07.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"doi": "10.1101/12345678" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"doi": "10.1101/12345678" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
# Get the server name from the command-line argument | ||
server=$1 | ||
|
||
most_recent_file=$(ls -1 data/rxivx/${server}/downloaded | sort -r | head -n 1) | ||
latest_date=$(echo $most_recent_file | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}' | tail -1) | ||
current_date=$(date +'%Y-%m-%d') | ||
output_filename="${server}_${latest_date}_${current_date}.json" | ||
|
||
echo "Downloading ${output_filename} database" | ||
|
||
makim scheduler.download-rxivr --server ${server} --begin ${latest_date} --end ${current_date} --target data/rxivx/${server}/downloaded/ | ||
|
||
python merge_arxiv_data.py "data/rxivx/${server}/final/${server}_full_data.json" "data/rxivx/${server}/downloaded/${output_filename}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
import sys | ||
|
||
def merge_json_files(existing_file_path: str, new_file_path: str) -> None: | ||
""" | ||
Merge the data from a new JSON file into an existing JSON file, avoiding duplicates based on the 'doi' field. | ||
Args: | ||
existing_file_path (str): The path to the existing JSON file. | ||
new_file_path (str): The path to the new JSON file. | ||
Returns: | ||
None | ||
""" | ||
existing_dois = set() | ||
with open(existing_file_path, 'r') as f: | ||
existing_data = json.load(f) | ||
for entry in existing_data: | ||
existing_dois.add(entry['doi']) | ||
|
||
with open(new_file_path, 'r') as f: | ||
new_data = json.load(f) | ||
merged_data = existing_data.copy() | ||
for entry in new_data: | ||
if entry['doi'] not in existing_dois: | ||
merged_data.append(entry) | ||
|
||
with open(existing_file_path, 'w') as f: | ||
json.dump(merged_data, f, indent=4) | ||
|
||
if __name__ == '__main__': | ||
# Get the file paths from the command line arguments | ||
existing_file_path = sys.argv[1] | ||
new_file_path = sys.argv[2] | ||
|
||
# Call the merge function | ||
merge_json_files(existing_file_path, new_file_path) |