This Python library extracts ORCID information from a file containing ORCID IDs and generates reports in various formats (TXT, PDF, JSON, CSV, Excel).
Project description
ORCID Data Extractor and Report Generator
This Python script extracts ORCID information from a file containing ORCID IDs and generates reports in various formats (TXT, PDF, JSON, CSV, Excel).
Table of Contents
Installation
- To install the
OrcidXtractlibrary, simply usepip:pip install OrcidXtract
Usage
Once the library is installed, you can use it from the command line with the orcidxtract command.
Command-Line Arguments
orcidxtract --help
Options:
-h, --help show this help message and exit
--inputfile INPUTFILE
Path to the input file containing ORCID IDs.
--orcid_ids [ORCID_IDS ...]
List of ORCID IDs (e.g., 0000-0001-...).
--output-format {txt,pdf,json} [{txt,pdf,json} ...]
Specify one or more output formats (txt, pdf, json).
Example: --output-format txt pdf json
--report {csv,excel} Specify if you want to generate a CSV or Excel report.
Example: --report csv
The script accepts the following command-line arguments:
--inputfile: Path to the input file containing ORCID IDs.--orcid_ids: A list of ORCID IDs (e.g.,0000-0001-5109-3700).--output-format: Specify one or more output formats (txt, pdf, json). Example:--output-format txt pdf json.--report: Specify if you want to generate a CSV or Excel report.
Example Commands
- Extract ORCID data and generate TXT, PDF, and JSON reports:
orcidxtract --inputfile orcid_ids.txt --output-format txt pdf json
- Extract ORCID data and generate a CSV report:
orcidxtract --inputfile orcid_ids.txt --output-format txt --report csv
- Extract ORCID data and generate an Excel report:
orcidxtract --inputfile orcid_ids.txt --output-format json --report excel
- Extract ORCID directly from the command line (Work only for one ORCID id at a time):
orcidxtract --orcid_ids xxxx-xxxx-xxxx-xxxx --output-format txt pdf json --report csv
- Generate only Report
orcidxtract --orcid_ids xxxx-xxxx-xxxx-xxxx --report csv
Function Details
Fetching ORCID Data: get_orcid_data(orcid_id: str)
This function fetches ORCID profile information using an ORCID ID.
Parameters:
orcid_id(str): The ORCID ID of the researcher.
Returns:
- An
OrcidDataobject containing ORCID profile details.
Generate File: create_report(orcid_data: list, format: str)
he library provides multiple functions to generate files in different formats: TXT, PDF, and JSON.
Functions:
create_txt(file_path: str, orcid_info: OrcidData)create_pdf(file_path: str, orcid_info: OrcidData)create_json(file_path: str, orcid_info: OrcidData)
Parameters:
file_path(str): The output path where the JSON file should be saved.orcid_info(OrcidData): The ORCID data object.
Generating Reports: create_report(orcid_data: list, format: str)
Generates a report in CSV or Excel format, containing multiple ORCID profiles.
Parameters:
orcid_data(list): A list of OrcidData objects.format(str): The format of the report (csv or excel).
Using in Python Code
To integrate the library into a Python script, follow these steps.
-
Import the Required Functions
from OrcidXtract.orcid_extractor import get_orcid_data from OrcidXtract.report_generator import create_txt, create_pdf, create_json, create_report
-
Define the ORCID IDs
You can manually define ORCID IDs or read them from a file.
# Define ORCID IDs to fetch data for orcid_ids = ["0000-0002-2140-1538", "0009-0003-9071-3804"] # Read ORCID IDs from a file input_file = "input_file.txt" with open(input_file, "r") as f: orcid_ids = [line.strip() for line in f if line.strip()]
-
Set Output Formats
Specify the output formats (txt, pdf, json) and report type (csv or excel).
output_formats = ["txt", "json", "pdf"] # Choose desired formats report_format = "csv" # Change to "excel" if needed
-
Fetch ORCID Data and Generate Reports
orcid_data = [] for orcid_id in orcid_ids: orcid_info = get_orcid_data(orcid_id) orcid_data.append(orcid_info) # Save reports only in the specified formats if "txt" in output_formats: create_txt(f"{orcid_id}.txt", orcid_info) if "pdf" in output_formats: create_pdf(f"{orcid_id}.pdf", orcid_info) if "json" in output_formats: create_json(f"{orcid_id}.json", orcid_info)
-
Generate a Summary Report (CSV/Excel)
create_report(orcid_data, report_format) # Generates a CSV or Excel report
Input File Format
The input file should contain one ORCID ID per line. Example (orcid_ids.txt):
0000-0000-0000-0001
0000-0000-0000-0002
0000-0000-0000-0003
Output Files
The generated reports will be saved in the Result directory. The directory structure will look like this:
Result
- 0000-0000-0000-0001.txt
- 0000-0000-0000-0002.pdf
- 0000-0000-0000-0003.json
- orcid_report.csv
- orcid_report.xlsx
Features
- ORCID Data Extraction: Extracts detailed information from ORCID IDs.
- Multiple Output Formats: Supports TXT, PDF, JSON, CSV, and Excel formats.
- Customizable Reports: Generate reports based on specific requirements.
- Error Handling: Handles missing or invalid data gracefully.
- Automatic Output Handling: All reports are saved in the
Resultfolder.
Dependencies
- argparse: For parsing command-line arguments.
- reportlab: For generating PDF reports.
- pandas: For generating CSV and Excel reports.
- requests: For making HTTP requests to ORCID's API.
- openpyxl: For working with Excel files.
These dependencies will be automatically installed when you install the package via pip.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions
For any questions or issues, please open an issue on the GitHub repository. If you'd like to contribute, please fork the repository and submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orcidxtract-0.0.6.tar.gz.
File metadata
- Download URL: orcidxtract-0.0.6.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c35b3a42899ce197fee719ece4a0746a930a127b80c7dbeaed8ac76a9d0f49d1
|
|
| MD5 |
a5767dfa23505610aef96a335fa78f40
|
|
| BLAKE2b-256 |
0028cc850d05bc20d2fa07128ca1ecca7c91ef256f17c126281a4f4be0cd063f
|
File details
Details for the file OrcidXtract-0.0.6-py3-none-any.whl.
File metadata
- Download URL: OrcidXtract-0.0.6-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21208c8dcdb154b0536f1315fea5c5d6a71287e0e2a4f48d240cf2849a5fe745
|
|
| MD5 |
9ef0098f898a355988c34d20e4a1a101
|
|
| BLAKE2b-256 |
ba3657f1c6c59b628a0cfc7b865a90fbf0e9261d98acf4058940c67b1ef51ae8
|