Skip to content

Commit

Permalink
Merge pull request #108 from semantic-systems/feature/ieee-integration
Browse files Browse the repository at this point in the history
IEEE integration
  • Loading branch information
huntila authored Jul 18, 2023
2 parents d2d4c86 + 3ae2017 commit d737b0b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
80 changes: 80 additions & 0 deletions ieee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import requests
import logging
import utils
from objects import Article

logger = logging.getLogger('nfdi_search_engine')


def search(search_term, results):
# API key and
api_key = '4nm2vdr778weget78v9ubgdb'
# maximum number of records to retrieve, it's changable
max_records = 1000

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'nfdi4dsBot/1.0 (https://www.nfdi4datascience.de/nfdi4dsBot/; [email protected])'
}

# search URL with the provided search term, API key, and max records
search_url = f'http://ieeexploreapi.ieee.org/api/v1/search/articles?querytext={search_term}&apikey={api_key}&max_records={max_records}'

try:
# Send GET request to the search URL
response = requests.get(search_url, headers=headers)

# Logging the response details
logger.debug(f'Ieee response status code: {response.status_code}')
logger.debug(f'Ieee response headers: {response.headers}')

# Check if the request was successful (status code 200)
if response.status_code == 200:
# Extract the JSON response
data = response.json()

# Check if there are any articles found
if 'articles' in data:
articles = data['articles']
for article in articles:
# Extract article information from the JSON response
title = article.get('title', '')
description = article.get('abstract', '')
short_description = utils.remove_html_tags(description)
publication_date = article.get('publication_date', '')
url = article.get('html_url', '')

authors_list = ''
if 'authors' in article:
authors = article['authors']['authors']
# Concatenate authors' names with a comma separator
authors_list = ', '.join([author.get('full_name', '') for author in authors])

# Create an Article object and add it to the results list
results.append(
Article(
title=title,
url=url,
authors=authors_list,
description=short_description,
date=publication_date,
)
)

else:
print("No results found for the search term:", search_term)
else:
print("Failed to retrieve the data:", response.text)

# Logging the number of records retrieved from Ieee
logger.info(f'Got {len(results)} records from Ieee')

except requests.exceptions.RequestException as e:
print("An error occurred during the request:", str(e))
except KeyError as ke:
print("Key not found:", str(ke))
except ValueError as ve:
print("Invalid JSON response:", str(ve))
except Exception as ex:
print("An unexpected error occurred:", str(ex))
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import logging.config
import os
import uuid

import details_page
from objects import Person, Zenodo, Article, Dataset, Presentation, Poster, Software, Video, Image, Lesson, Institute, Funder, Publisher, Gesis, Cordis, Orcid, Gepris
from flask import Flask, render_template, request, make_response
import threading
import dblp, zenodo, openalex, resodate, wikidata, cordis, gesis, orcid, gepris # , eulg
import details_page
import dblp, zenodo, openalex, resodate, wikidata, cordis, gesis, orcid, gepris, ieee #eulg
# import dblp, zenodo, openalex, resodate, wikidata, cordis, gesis, orcid, gepris # , eulg

logging.config.fileConfig(os.getenv('LOGGING_FILE_CONFIG', './logging.conf'))
logger = logging.getLogger('nfdi_search_engine')
Expand Down Expand Up @@ -45,7 +47,7 @@ def sources():
# add all the sources here in this list; for simplicity we should use the exact module name
# ensure the main method which execute the search is named "search" in the module
# sources = [dblp, zenodo, openalex, resodate, wikidata, cordis, gesis]
sources = [dblp, zenodo, openalex, resodate, wikidata, cordis, gesis, orcid, gepris] #, eulg]
sources = [dblp, zenodo, openalex, resodate, wikidata, cordis, gesis, orcid, gepris, ieee] #, eulg]

for source in sources:
t = threading.Thread(target=source.search, args=(search_term, results,))
Expand Down

0 comments on commit d737b0b

Please sign in to comment.