112 lines
4.0 KiB
Python
112 lines
4.0 KiB
Python
#####################################################
|
|
# Title: SLR Helper (slr_helper)
|
|
# Author: Jesper Bergman (jesperbe@dsv.su.se)
|
|
# Licence: GPLv3
|
|
#####################################################
|
|
|
|
#!/usr/bin/python
|
|
"""SLR Helper - Systematic Literature Review Helper
|
|
|
|
|
|
SLR Helper is small program that helps you do systematic literature
|
|
reviews by fetching academic works and sieving through their abstracts using
|
|
inclusion/exclusion criteria.
|
|
|
|
Usage:
|
|
slr_helper.py -i <input_file.json>
|
|
slr_helper.py -a <api_key> -k <keywords>
|
|
slr_helper.py -a <api_key> -k <keywords> -h <hits>
|
|
|
|
Examples:
|
|
slr_helper.py -i -o -x
|
|
slr_helper.py -a <api_key> -u <url> -k <keywords> -s <subject>
|
|
slr_helper.py -i <input_file.json> -m <"nb", or "svm", or "lr", or "rf", or "dt", or "ALL" (default)>
|
|
|
|
Options:
|
|
-a --api_key For downloading: API key (supported now: Scopus, IEEExplore)
|
|
-i --input For sieving: Input file(s) to sieve through
|
|
-k --keywords For downloading: Keywords to search for on the URL (i.e. academic database) used
|
|
-o --operator For downloading: Search operators (OR, AND)
|
|
-x --expression For sieving: Reg ex to filter [default: ALL]
|
|
-s --subject Specification of subject matter [default: ALL]. E.g. "COMP" or "AGRI"
|
|
-d --database For sieving: Database to store the results in [default: NONE]
|
|
-u --url For downloading: Academic database (or search engine) URL [default: Scopus].
|
|
-h --hits Number of results to fetch [default: 25].
|
|
"""
|
|
|
|
# Import standard libraries
|
|
from docopt import docopt
|
|
import sys
|
|
import requests as req
|
|
import json
|
|
|
|
# Main menu
|
|
def main(arguments):
|
|
# Extract arguments of interest
|
|
input_file = arguments['<input_file.json>']
|
|
api_key = arguments['<api_key>']
|
|
#url = arguments['<url>']
|
|
#url = "https://api.elsevier.com/content/search/scopus?query="
|
|
url = "https://api.elsevier.com/content/search/scopus?query="
|
|
keywords = arguments['<keywords>']
|
|
search_engine = "scopus"
|
|
#hits = str("&cursor=*&count=" + arguments["<hits>"]) # If more than 25 hits
|
|
|
|
if input_file:
|
|
with open(input_file) as json_file:
|
|
json_data = json.load(json_file)
|
|
for key, value in json_data.items():
|
|
for i in value['entry']:
|
|
print(i, "\n\n")
|
|
|
|
else:
|
|
fetch_scopus(api_key, url, keywords)
|
|
|
|
def fetch_scopus(api_key, url, keywords):
|
|
|
|
if api_key:
|
|
query = str(url + keywords + "&apiKey=" + api_key)
|
|
query_response = req.get(query)
|
|
dta = query_response.json()
|
|
print_summary(dta)
|
|
if query_response.status_code == 429:
|
|
print("Error 429")
|
|
if query_response.status_code != 200:
|
|
print("Not 200!")
|
|
|
|
def fetch_next_scopus(url):
|
|
print("Fetching next 25: ", url)
|
|
response = req.get(url, headers ={"Accept" : "application/json"})
|
|
data = response.json()
|
|
print(type(data))
|
|
print_summary(data)
|
|
if query_response.status_code == 429:
|
|
print("Error 429")
|
|
if query_response.status_code != 200:
|
|
print("Not 200!")
|
|
|
|
|
|
def extract_scopus_results(results_json):
|
|
print("JSON")
|
|
|
|
def extract_ieee_results(results_xml):
|
|
print("XML")
|
|
|
|
def print_summary(total_articles):
|
|
print("Printing summary\n------------------\nTotal hits: ", total_articles["search-results"]["opensearch:totalResults"])
|
|
print("\nSearch word:", total_articles["search-results"]["opensearch:Query"]["@searchTerms"], "\n\n--------------------")
|
|
total_articles_list = total_articles["search-results"]["entry"]
|
|
|
|
for i in total_articles_list:
|
|
print("Title:", i["dc:title"],"\nAuthors:", i["dc:creator"],"\nPublication:", i["prism:publicationName"],"\nType:", i["prism:aggregationType"], i["subtypeDescription"], "\n\n")
|
|
|
|
for ln in total_articles["search-results"]["link"]:
|
|
if ln["@ref"] == "next":
|
|
print(ln["@href"])
|
|
fetch_next_scopus(ln["@href"])
|
|
|
|
# Main menu constructor
|
|
if __name__ == "__main__":
|
|
arguments = docopt(__doc__, version='slr_helper 0.1')
|
|
main(arguments)
|