Skip to content

Commit 8e1386e

Browse files
Some code cleanup to adhere to PEP8
1 parent 202f3f2 commit 8e1386e

File tree

10 files changed

+61
-94
lines changed

10 files changed

+61
-94
lines changed

pybliometrics/sciencedirect/article_metadata.py

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from typing import List, NamedTuple, Optional, Tuple, Union
33

44
from pybliometrics.superclasses import Search
5-
from pybliometrics.utils import check_field_consistency, chained_get, check_integrity,\
6-
check_parameter_value, deduplicate, make_search_summary, VIEWS
5+
from pybliometrics.utils import check_field_consistency, chained_get, \
6+
check_integrity, check_parameter_value, deduplicate, \
7+
make_search_summary, VIEWS
78

89

910
class ArticleMetadata(Search):
@@ -47,39 +48,39 @@ def results(self) -> Optional[List[NamedTuple]]:
4748
first_author = item.get('dc:creator')[0].get('$')
4849
link = item.get('link')[0].get('@href')
4950
doi = item.get("prism:doi") or item.get("dc:identifier")[4:] if item.get("dc:identifier") else None
50-
new = doc(authorKeywords=item.get('authkeywords'),
51-
authors=authors,
52-
available_online_date=item.get('available-online-date'),
53-
first_author=first_author,
54-
abstract_text=item.get('dc:description'),
55-
doi=doi,
56-
title=item.get('dc:title'),
57-
eid=item.get('eid'),
58-
link=link,
59-
openArchiveArticle=item.get('openArchiveArticle'),
60-
openaccess_status=item.get('openaccess'),
61-
openaccessArticle=item.get('openaccessArticle'),
62-
openaccessUserLicense=item.get('openaccessUserLicense'),
63-
pii=item.get('pii'),
64-
aggregationType=item.get('prism:aggregationType'),
65-
copyright=item.get('prism:copyright'),
66-
coverDate=item.get('prism:coverDate'),
67-
coverDisplayDate=item.get('prism:coverDisplayDate'),
68-
edition=item.get('prism:edition'),
69-
endingPage=item.get('prism:endingPage'),
70-
isbn=item.get('prism:isbn'),
71-
publicationName=item.get('prism:publicationName'),
72-
startingPage=item.get('prism:startingPage'),
73-
teaser=item.get('prism:teaser'),
74-
api_link=item.get('prism:url'),
75-
publicationType=item.get('pubType'),
76-
vor_available_online_date=item.get('vor-available-online-date'),
77-
)
51+
new = doc(
52+
authorKeywords=item.get('authkeywords'),
53+
authors=authors,
54+
available_online_date=item.get('available-online-date'),
55+
first_author=first_author,
56+
abstract_text=item.get('dc:description'),
57+
doi=doi,
58+
title=item.get('dc:title'),
59+
eid=item.get('eid'),
60+
link=link,
61+
openArchiveArticle=item.get('openArchiveArticle'),
62+
openaccess_status=item.get('openaccess'),
63+
openaccessArticle=item.get('openaccessArticle'),
64+
openaccessUserLicense=item.get('openaccessUserLicense'),
65+
pii=item.get('pii'),
66+
aggregationType=item.get('prism:aggregationType'),
67+
copyright=item.get('prism:copyright'),
68+
coverDate=item.get('prism:coverDate'),
69+
coverDisplayDate=item.get('prism:coverDisplayDate'),
70+
edition=item.get('prism:edition'),
71+
endingPage=item.get('prism:endingPage'),
72+
isbn=item.get('prism:isbn'),
73+
publicationName=item.get('prism:publicationName'),
74+
startingPage=item.get('prism:startingPage'),
75+
teaser=item.get('prism:teaser'),
76+
api_link=item.get('prism:url'),
77+
publicationType=item.get('pubType'),
78+
vor_available_online_date=item.get('vor-available-online-date'),
79+
)
7880
out.append(new)
7981
check_integrity(out, self._integrity, self._action)
8082
return out or None
8183

82-
8384
def __init__(self,
8485
query: str,
8586
refresh: Union[bool, int] = False,
@@ -162,12 +163,10 @@ def __init__(self,
162163
Search.__init__(self, query=query, api="ArticleMetadata", size=size,
163164
download=download, verbose=verbose, **kwds)
164165

165-
166166
def __str__(self):
167167
"""Print a summary string."""
168168
return make_search_summary(self, "document", self.get_eids())
169169

170-
171170
def get_eids(self):
172171
"""EIDs of retrieved documents."""
173172
return [d['eid'] for d in self._json]

pybliometrics/sciencedirect/article_retrieval.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,36 @@ def abstract(self) -> Optional[str]:
2323
abstract = abstract.strip()
2424
return abstract
2525

26-
2726
@property
2827
def aggregationType(self) -> Optional[str]:
2928
"""The aggregation type of a document."""
3029
return chained_get(self._json, ['coredata', 'prism:aggregationType'])
3130

32-
3331
@property
3432
def authors(self) -> Optional[list]:
3533
"""The authors of a document."""
3634
out = []
3735
auth = namedtuple('Author', 'surname given_name')
3836
for author in chained_get(self._json, ['coredata', 'dc:creator']):
3937
surname, given_name = author['$'].split(',')
40-
new = auth(surname=surname,
41-
given_name=given_name)
38+
new = auth(surname=surname, given_name=given_name)
4239
out.append(new)
4340
return out or None
4441

45-
4642
@property
4743
def copyright(self) -> Optional[str]:
4844
"""The copyright of a document."""
4945
return chained_get(self._json, ['coredata', 'prism:copyright'])
5046

51-
5247
@property
5348
def coverDate(self) -> Optional[str]:
5449
"""The date of the cover the document is in."""
5550
return chained_get(self._json, ['coredata', 'prism:coverDate'])
5651

57-
5852
@property
5953
def coverDisplayDate(self) -> Optional[str]:
6054
"""The cover display date of a document."""
6155
return chained_get(self._json, ['coredata', 'prism:coverDisplayDate'])
62-
6356

6457
@property
6558
def document_entitlement_status(self) -> Optional[str]:
@@ -69,106 +62,89 @@ def document_entitlement_status(self) -> Optional[str]:
6962
"""
7063
return chained_get(self._json, ['document-entitlement', 'status'])
7164

72-
7365
@property
7466
def doi(self) -> str:
7567
"""The doi of a document."""
7668
return chained_get(self._json, ['coredata', 'prism:doi'])
7769

78-
7970
@property
8071
def eid(self) -> Optional[str]:
8172
"""The eid of a document."""
8273
return chained_get(self._json, ['coredata', 'eid'])
8374

84-
8575
@property
8676
def endingPage(self) -> Optional[str]:
8777
"""The ending page of a document."""
8878
page = chained_get(self._json, ['coredata', 'prism:endingPage'])
8979
return page
9080

91-
9281
@property
9382
def issn(self) -> int:
9483
"""The issn of a document."""
9584
return make_int_if_possible(chained_get(self._json, ['coredata', 'prism:issn']))
9685

97-
9886
@property
9987
def openaccess(self) -> bool:
10088
"""The document is open access."""
10189
open_access = chained_get(self._json, ['coredata', 'openaccessArticle'])
10290
return make_bool_if_possible(open_access)
10391

104-
10592
@property
10693
def openaccessSponsorName(self) -> Optional[str]:
10794
"""The open access sponsor name of a document."""
10895
return chained_get(self._json, ['coredata', 'openaccessSponsorName'])
10996

110-
11197
@property
11298
def openaccessSponsorType(self) -> Optional[str]:
11399
"""The open access sponsor type of a document."""
114100
return chained_get(self._json, ['coredata', 'openaccessSponsorType'])
115101

116-
117102
@property
118103
def openaccessType(self) -> Optional[str]:
119104
"""The open access type of a document."""
120105
return chained_get(self._json, ['coredata', 'openaccessType'])
121106

122-
123107
@property
124108
def openaccessUserLicense(self) -> Optional[str]:
125109
"""The open access user license of a document."""
126110
return chained_get(self._json, ['coredata', 'openaccessUserLicense'])
127111

128-
129112
@property
130113
def openArchiveArticle(self) -> bool:
131114
"""The document is an open archive article."""
132115
open_archive = chained_get(self._json, ['coredata', 'openArchiveArticle'])
133116
return make_bool_if_possible(open_archive)
134117

135-
136118
@property
137119
def originalText(self) -> Optional[str]:
138120
"""Complete document text."""
139121
return self._json.get('originalText')
140122

141-
142123
@property
143124
def pageRange(self) -> Optional[str]:
144125
"""The prism:pageRange of a document."""
145126
return chained_get(self._json, ['coredata', 'prism:pageRange'])
146127

147-
148128
@property
149129
def publicationName(self) -> str:
150130
"""The publication name of a document (e.g. Journal of Economy and Technology)."""
151131
return chained_get(self._json, ['coredata', 'prism:publicationName'])
152132

153-
154133
@property
155134
def publisher(self) -> Optional[str]:
156135
"""The publisher of a document."""
157136
return chained_get(self._json, ['coredata', 'prism:publisher'])
158137

159-
160138
@property
161139
def pubType(self) -> Optional[str]:
162140
"""The publication type of a document."""
163141
return chained_get(self._json, ['coredata', 'pubType'])
164142

165-
166143
@property
167144
def pii(self) -> str:
168145
"""The pii of a document."""
169146
return chained_get(self._json, ['coredata', 'pii'])
170147

171-
172148
@property
173149
def sciencedirect_link(self) -> str:
174150
"""The ScienceDirect link of a document."""
@@ -177,7 +153,6 @@ def sciencedirect_link(self) -> str:
177153
if link['@rel'] == 'scidir':
178154
return link['@href']
179155

180-
181156
@property
182157
def self_link(self) -> str:
183158
"""The API link of a document."""
@@ -186,39 +161,33 @@ def self_link(self) -> str:
186161
if link['@rel'] == 'self':
187162
return link['@href']
188163

189-
190164
@property
191165
def startingPage(self) -> Optional[str]:
192166
"""The starting page of a document."""
193167
return chained_get(self._json, ['coredata', 'prism:startingPage'])
194168

195-
196169
@property
197170
def subjects(self) -> Optional[str]:
198171
"""The subjects of a document."""
199172
subjects = chained_get(self._json, ['coredata', 'dcterms:subject'])
200173
return [subject['$'] for subject in subjects]
201174

202-
203175
@property
204176
def title(self) -> str:
205177
"""The title of a document."""
206178
return chained_get(self._json, ['coredata', 'dc:title'])
207179

208-
209180
@property
210181
def url(self) -> str:
211182
"""The url of a document."""
212183
return chained_get(self._json, ['coredata', 'prism:url'])
213184

214-
215185
@property
216186
def volume(self) -> Optional[str]:
217187
"""The prism:volume of a document."""
218188
vol = chained_get(self._json, ['coredata', 'prism:volume'])
219189
return make_int_if_possible(vol)
220190

221-
222191
def __init__(self,
223192
identifier: Union[int, str] = None,
224193
refresh: Union[bool, int] = False,
@@ -250,7 +219,6 @@ def __init__(self,
250219
if self._view != "ENTITLED":
251220
self._json = self._json['full-text-retrieval-response']
252221

253-
254222
def __str__(self):
255223
s = ''
256224
if self._view in ('FULL', 'META_ABS', 'META'):

pybliometrics/sciencedirect/sciencedirect_search.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
from typing import List, NamedTuple, Optional, Tuple, Union
33

44
from pybliometrics.superclasses import Search
5-
from pybliometrics.utils import check_field_consistency, chained_get, check_integrity,\
6-
check_parameter_value, deduplicate, make_search_summary, VIEWS
5+
from pybliometrics.utils import check_field_consistency, chained_get, \
6+
check_integrity, check_parameter_value, deduplicate, \
7+
make_search_summary, VIEWS
78

89

910
class ScienceDirectSearch(Search):
@@ -49,7 +50,8 @@ def results(self) -> Optional[List[NamedTuple]]:
4950
links['scidir'] = link.get('@href')
5051
# Get doi
5152
doi = item.get("prism:doi") or item.get("dc:identifier")[4:] if item.get("dc:identifier") else None
52-
new = doc(authors=authors,
53+
new = doc(
54+
authors=authors,
5355
first_author=item.get('dc:creator'),
5456
doi=doi,
5557
title=item.get("dc:title"),
@@ -62,7 +64,8 @@ def results(self) -> Optional[List[NamedTuple]]:
6264
publicationName=item.get("prism:publicationName"),
6365
startingPage=item.get("prism:startingPage"),
6466
api_link=links["api_link"] or item.get("prism:url"),
65-
volume=item.get("prism:volume"))
67+
volume=item.get("prism:volume")
68+
)
6669
out.append(new)
6770
check_integrity(out, self._integrity, self._action)
6871
return out or None

pybliometrics/scopus/abstract_retrieval.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from typing import List, NamedTuple, Optional, Tuple, Union
33

44
from pybliometrics.superclasses import Retrieval
5-
from pybliometrics.utils import chained_get, check_parameter_value,\
6-
deduplicate, get_id, detect_id_type, get_link, listify,\
5+
from pybliometrics.utils import chained_get, check_parameter_value, \
6+
deduplicate, get_id, detect_id_type, get_link, listify, \
77
make_int_if_possible, parse_date_created, VIEWS
88

99

@@ -287,7 +287,6 @@ def document_entitlement_status(self) -> Optional[str]:
287287
Note: Only works with `ENTITLED` view.
288288
"""
289289
return chained_get(self._json, ['document-entitlement', 'status'])
290-
291290

292291
@property
293292
def doi(self) -> Optional[str]:
@@ -755,10 +754,10 @@ def __str__(self):
755754
view="META_ABS" or view="FULL".
756755
"""
757756
def convert_citedbycount(entry):
758-
try:
759-
return float(entry.citedbycount) or 0
760-
except (ValueError, TypeError):
761-
return 0
757+
try:
758+
return float(entry.citedbycount) or 0
759+
except (ValueError, TypeError):
760+
return 0
762761

763762
def get_date(coverDate):
764763
try:
@@ -791,14 +790,14 @@ def get_date(coverDate):
791790
s += "\n Affiliation(s):\n "
792791
s += '\n '.join([aff.name for aff in self.affiliation])
793792

794-
elif self._view in ('REF'):
793+
elif self._view in ('REF',):
795794
try:
796795
# Sort reference list by citationcount
797796
top_n = 5
798797
references = sorted(self.references, key=convert_citedbycount, reverse=True)
799798

800-
top_references = [f'{reference.title} ({get_date(reference.coverDate)}). '+
801-
f'EID: {reference.id}' for reference in references[:top_n]]
799+
top_references = [f'{reference.title} ({get_date(reference.coverDate)}). ' +
800+
f'EID: {reference.id}' for reference in references[:top_n]]
802801
except TypeError:
803802
top_n = 0
804803

pybliometrics/scopus/affiliation_retrieval.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List, NamedTuple, Optional, Tuple, Union
33

44
from pybliometrics.superclasses import Retrieval
5-
from pybliometrics.utils import chained_get, check_parameter_value,\
5+
from pybliometrics.utils import chained_get, check_parameter_value, \
66
get_id, get_link, parse_date_created, make_int_if_possible, VIEWS
77

88

0 commit comments

Comments
 (0)