forked from ElsevierDev/elsapy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleProg.py
More file actions
107 lines (90 loc) · 3.48 KB
/
exampleProg.py
File metadata and controls
107 lines (90 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""An example program that uses the elsapy module."""
import json
from elsapy.elsclient import ElsClient
from elsapy.elsdoc import AbsDoc, FullDoc
from elsapy.elsprofile import ElsAffil, ElsAuthor
from elsapy.elssearch import ElsSearch
## Load configuration
con_file = open("config.json")
config = json.load(con_file)
con_file.close()
## Initialize client
client = ElsClient(config["apikey"])
client.inst_token = config["insttoken"]
## Author example
# Initialize author with uri
my_auth = ElsAuthor(uri="https://api.elsevier.com/content/author/author_id/7004367821")
# Read author data, then write to disk
if my_auth.read(client):
print("my_auth.full_name: ", my_auth.full_name)
my_auth.write()
else:
print("Read author failed.")
## Affiliation example
# Initialize affiliation with ID as string
my_aff = ElsAffil(affil_id="60101411")
if my_aff.read(client):
print("my_aff.name: ", my_aff.name)
my_aff.write()
else:
print("Read affiliation failed.")
## Scopus (Abtract) document example
# Initialize document with ID as integer
scp_doc = AbsDoc(scp_id=84872135457)
if scp_doc.read(client):
print("scp_doc.title: ", scp_doc.title)
scp_doc.write()
else:
print("Read document failed.")
## ScienceDirect (full-text) document example using PII
pii_doc = FullDoc(sd_pii="S1674927814000082")
if pii_doc.read(client):
print("pii_doc.title: ", pii_doc.title)
pii_doc.write()
else:
print("Read document failed.")
## ScienceDirect (full-text) document example using DOI
doi_doc = FullDoc(doi="10.1016/S1525-1578(10)60571-5")
if doi_doc.read(client):
print("doi_doc.title: ", doi_doc.title)
doi_doc.write()
else:
print("Read document failed.")
## Load list of documents from the API into affilation and author objects.
# Since a document list is retrieved for 25 entries at a time, this is
# a potentially lenghty operation - hence the prompt.
print("Load documents (Y/N)?")
s = input("--> ")
if s == "y" or s == "Y":
## Read all documents for example author, then write to disk
if my_auth.read_docs(client):
print("my_auth.doc_list has " + str(len(my_auth.doc_list)) + " items.")
my_auth.write_docs()
else:
print("Read docs for author failed.")
## Read all documents for example affiliation, then write to disk
if my_aff.read_docs(client):
print("my_aff.doc_list has " + str(len(my_aff.doc_list)) + " items.")
my_aff.write_docs()
else:
print("Read docs for affiliation failed.")
## Initialize author search object and execute search
auth_srch = ElsSearch("authlast(keuskamp)", "author")
auth_srch.execute(client)
print("auth_srch has", len(auth_srch.results), "results.")
## Initialize affiliation search object and execute search
aff_srch = ElsSearch("affil(amsterdam)", "affiliation")
aff_srch.execute(client)
print("aff_srch has", len(aff_srch.results), "results.")
## Initialize doc search object using Scopus and execute search, retrieving
# all results
doc_srch = ElsSearch(
"AFFIL(dartmouth) AND AUTHOR-NAME(lewis) AND PUBYEAR > 2011", "scopus"
)
doc_srch.execute(client, get_all=True)
print("doc_srch has", len(doc_srch.results), "results.")
## Initialize doc search object using ScienceDirect and execute search,
# retrieving all results
doc_srch = ElsSearch("star trek vs star wars", "sciencedirect")
doc_srch.execute(client, get_all=False)
print("doc_srch has", len(doc_srch.results), "results.")