-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_outputs.py
53 lines (41 loc) · 1.5 KB
/
get_outputs.py
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
"""Retrieves outputs from Zenodo CCG group
dict_keys(['creator', 'date', 'description', 'identifier', 'language', 'relation', 'rights', 'subject', 'title', 'type'])
"""
from csv import writer
from sickle import Sickle
URL = """https://zenodo.org/oai2d?verb=ListRecords&set=user-ccg&metadataPrefix=oai_dc"""
si = Sickle(URL)
records = si.ListRecords(metadataPrefix='oai_dc')
repositories = {}
for record in records:
md = record.metadata
relation = md['relation'][0]
if relation in repositories:
stamp = record.header.datestamp
exist_stamp = repositories[relation].header.datestamp
if stamp > exist_stamp:
repositories[relation] = record
else:
repositories[relation] = record
citations = []
for record in repositories.values():
md = record.metadata
try:
title = md['title'][0]
except KeyError:
title = ''
output_type = md['type'][1]
authors = []
for author in md['creator']:
try:
lastname, firstname = author.split(",")
except ValueError:
firstname, lastname = author.split(" ")
initial = firstname.strip()[0]
authors.append("{}, {}.".format(lastname, initial))
year = md['date'][0].strip()[0:4]
citation = "{}, {}, {}, {}, {}, {}".format(", ".join(authors), year, title, md['date'][0], md['identifier'][0], output_type)
citations.append(citation)
with open('outputs.txt', 'w') as textfile:
for x in citations:
textfile.write("{}\n".format(x))