How to Retrieve Research Paper Data from the researchmap  Save It to a Word Document Using Python



# How to Retrieve Research Paper Data from the researchmap API and Save It to a Word Document Using Python

In this article, I will introduce how to use Python to retrieve research paper data from the researchmap API, format it, and save it to a Word document.

## Installing Necessary Libraries

First, install the necessary libraries. This operation only needs to be done once.

```bash
!pip install python-docx
```

## Overview

The following code retrieves paper data from the API in JSON format, processes and formats it, and then saves it to a Word document.

### Importing Necessary Libraries

First, import the necessary libraries.

```python
import requests
import json
from docx import Document
from docx.shared import RGBColor
```

### Retrieving Data from the researchmap API

Next, retrieve data from the researchmap API.

```python
url = "https://api.researchmap.jp/iwamitaku/published_papers"
response = requests.get(url)
jsonData = response.json()
```

### Displaying and Formatting the Data

Display and format the retrieved data.

```python
for i in range(len(jsonData['items'])):
    print(i)
    print(jsonData['items'][i])

for i in range(len(jsonData['items'])):
    item = jsonData['items'][i]
    author_list = []

    authors = item.get('authors', {}).get('en', ['No authors available'])
    title = item.get('paper_title', {}).get('en', 'Title not available')
    journal = item.get('publication_name', {}).get('en', 'Journal not available')
    date = item.get('publication_date', 'Date not available')
    vol = item.get('volume', 'Volume not available')
    doi = item.get('identifiers', {}).get('doi', ['DOI not available'])[0]

    for j in range(len(authors)):
        author = ''.join(authors[j].values()) if isinstance(authors[j], dict) else authors[j]
        author_list.append(author)

    print(', '.join(author_list))
    print(title)
    print(journal, vol, date)
    print('doi:', doi)
    print('')
```

### Storing the Data in a List

Store all the paper data in a list.

```python
papers = []

for i in range(len(jsonData['items'])):
    item = jsonData['items'][i]
    author_list = []

    authors = item.get('authors', {}).get('en', ['No authors available'])
    title = item.get('paper_title', {}).get('en', 'Title not available')
    journal = item.get('publication_name', {}).get('en', 'Journal not available')
    date = item.get('publication_date', 'Date not available')
    vol = item.get('volume', 'Volume not available')
    doi = item.get('identifiers', {}).get('doi', ['DOI not available'])[0]

    for j in range(len(authors)):
        author = ''.join(authors[j].values()) if isinstance(authors[j], dict) else authors[j]
        author_list.append(author)

    paper_format = [', '.join(author_list), title, ', '.join([journal, vol, date]), ' '.join(['doi:', doi])]
    papers.append('\n'.join(paper_format))

for paper in papers[:5]:
    print(paper)
    print("---")
```

### Saving to a Word Document

Finally, save the retrieved paper data to a Word document.

```python
doc = Document()
docx_file = 'publication_iwamitaku.docx'

heading = doc.add_heading('Research Achievements', level=1)
heading.runs[0].font.color.rgb = RGBColor(0, 0, 0)
subheading = doc.add_heading('Original Papers', level=2)
subheading.runs[0].font.color.rgb = RGBColor(0, 0, 0)

for paper in papers:
    p = doc.add_paragraph(paper, style='List Number')

doc.save(docx_file)
```

## Thanks ! 

This concludes the introduction on how to retrieve paper data from the researchmap API, format it, and save it to a Word document. Please let me know if you find some mistakes and things needed to be updated.

---