1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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.

!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.

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.

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.

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.

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.

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.


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?