Research Journal Ranks Scopus With APIs Elsevier Developer Portal


#Langkah Ke-1: Instalasi library Modul Elsevier

pip install elsapy

#Langkah Ke-2: Membuat Konfigurasi File & Menambahkan API key

 import os


# Create the config file if it doesn't exist
config_file_path = "config.txt"
if not os.path.exists(config_file_path):
    with open(config_file_path, "w") as f:
        f.write("pip install elsapy\n")
        f.write("Masukkan kode API key disini")  # Replace with your actual API key
    print(f"Config file '{config_file_path}' created successfully.")
else:
    print(f"Config file '{config_file_path}' already exists.")

# Install elsapy if needed
!pip install elsapy

#Langkah Ke-3: Pemprosesan Library/Modul

"""An example program that uses the elsapy module"""

from elsapy.elsclient import ElsClient
from elsapy.elsprofile import ElsAuthor, ElsAffil
from elsapy.elsdoc import FullDoc, AbsDoc
from elsapy.elssearch import ElsSearch
import json

## Load configuration
# Changed config file name to "config.txt" and add logic to read API key
config_file_path = "config.txt"
with open(config_file_path, 'r') as f:
    for line in f:
        if line.startswith("APIKEY="):
            apikey = line.split("=")[1].strip()
            break  # Stop after finding API key
    else:
        apikey = None  # Handle case where API key is not found

# Creating config dict, assuming insttoken is not needed for this example
config = {
    'apikey': apikey,
    # 'insttoken': 'YOUR_INSTTOKEN'  # Uncomment and replace if needed
}

## Initialize client
client = ElsClient(config['apikey'])
# client.inst_token = config['insttoken']  # Uncomment if insttoken is in config

#Langkah Ke-4: Pembuatan Konfigurasi File json

import os
import json

# Create the config file if it doesn't exist
config_file_path = "config.json"  # Changed the file name to config.json
if not os.path.exists(config_file_path):
    config_data = {
        "apikey": "your_actual_api_key_here",  # Replace with your actual API key
        "insttoken": "your_actual_inst_token_here"  # Replace with your actual inst token
    }
    with open(config_file_path, "w") as f:
        json.dump(config_data, f)  # Use json.dump to write JSON data
    print(f"Config file '{config_file_path}' created successfully.")
else:
    print(f"Config file '{config_file_path}' already exists.")

#Langkah Ke-5: Jalankan Apikasi API key Scopus

import os
from elsapy.elsclient import ElsClient
from elsapy.elsprofile import ElsAuthor, ElsAffil
from elsapy.elsdoc import FullDoc, AbsDoc
from elsapy.elssearch import ElsSearch
import json

# Load API key from config.txt
config_file_path = "config.txt"
apikey = None
try:
    with open(config_file_path, 'r') as f:
        for line in f:
            if line.startswith("APIKEY="):
                apikey = line.split("=")[1].strip()
                break
except FileNotFoundError:
    print(f"Error: Config file '{config_file_path}' not found.")

if apikey is None:
    print("Error: API key not found in config.txt. Please provide a valid API key.")
    exit()  # Exit the script if the API key is not found

# Masukkan kode API key yang Anda telah buat dari Akun Website Elsevier Developer Portal
apikey = 'masukkan kode API key disini'

## Initialize client
client = ElsClient(apikey)

# Tulis Jurnal Artikel/Paper yang ingin Anda Cari dibawah ini
search_query = 'Tulis jurnal yang ingin dicari disini' # Example query, replace with your search terms
doc_srch = ElsSearch(search_query, 'scopus')
doc_srch.execute(client, get_all = True)
print("Total Results:", doc_srch.tot_num_res)


# Process search results
for i, doc in enumerate(doc_srch.results):
  print(f"\nResult {i+1}:")
  # Accessing data from the dictionary using keys
  print(f"Title: {doc.get('dc:title', 'N/A')}")  # Use get() to avoid KeyError if 'dc:title' is not present
  print(f"DOI: {doc.get('prism:doi', 'N/A')}")
  print(f"Publication Name: {doc.get('prism:publicationName', 'N/A')}")
  print(f"Year: {doc.get('prism:coverDate', 'N/A')[:4]}") #Extracting year from the coverDate, handling missing key
  print(f"URL: {doc.get('link', [{'href': 'N/A'}])[0].get('href', 'N/A')}") #Accessing URL, handling missing key and nested structure

  # Access other attributes as needed, using get() and appropriate keys

Semoga Bermanfaat :)
Read Also :-
Labels : #artikel ,
Memuat Info lainnya...
Writer, Creator, & Editor

Posting Komentar

Berikan pendapat terbaikmu mengenai postingan ini..