11
11
here = Path .cwd ()
12
12
13
13
with (here .parent / "codemeta.json" ).open () as fp :
14
- cm = load (fp )
14
+ cm = load (fp )
15
15
16
16
17
17
# print(cm)
18
18
19
19
20
20
def ordered_set (iterable ):
21
- return OrderedDict .fromkeys (iterable ).keys ()
21
+ return OrderedDict .fromkeys (iterable ).keys ()
22
22
23
23
24
24
uniq_affiliations = list (ordered_set (author ["affiliation" ] for author in cm ["author" ]))
25
25
26
26
27
27
def make_author (author ):
28
- data = {
29
- "name" : " " .join ([author ["givenName" ], author ["familyName" ]]),
30
- "affiliation" : uniq_affiliations .index (author .get ("affiliation" , "" )) + 1 ,
31
- }
32
- orcid_url = author .get ("@id" )
33
- if orcid_url :
34
- data .update ({"orcid" : Path (orcid_url ).name })
35
- return data
28
+ data = {
29
+ "name" : " " .join ([author ["givenName" ], author ["familyName" ]]),
30
+ "affiliation" : uniq_affiliations .index (author .get ("affiliation" , "" )) + 1 ,
31
+ }
32
+ orcid_url = author .get ("@id" )
33
+ if orcid_url :
34
+ data .update ({"orcid" : Path (orcid_url ).name })
35
+ return data
36
36
37
37
38
38
def make_affiliations ():
39
- return [{"name" : name , "index" : i + 1 } for i , name in enumerate (uniq_affiliations )]
39
+ return [{"name" : name , "index" : i + 1 } for i , name in enumerate (uniq_affiliations )]
40
40
41
41
42
42
def make_date (date ):
43
- date_parsed = datetime .strptime (date , "%Y-%m-%d" )
44
- return datetime .strftime (date_parsed , "%d %B %Y" )
43
+ date_parsed = datetime .strptime (date , "%Y-%m-%d" )
44
+ return datetime .strftime (date_parsed , "%d %B %Y" )
45
45
46
46
47
47
# Prepare data for metadata output
48
48
data = {
49
- "title" : cm .get ("title" , "" ),
50
- "tags" : cm .get ("keywords" , []),
51
- "authors" : [make_author (_ ) for _ in cm .get ("author" , [{}])],
52
- "affiliations" : make_affiliations (),
53
- "date" : make_date (cm .get ("dateModified" , "" )),
54
- "bibliography" : "paper.bib" ,
49
+ "title" : cm .get ("title" , "" ),
50
+ "tags" : cm .get ("keywords" , []),
51
+ "authors" : [make_author (_ ) for _ in cm .get ("author" , [{}])],
52
+ "affiliations" : make_affiliations (),
53
+ "date" : make_date (cm .get ("dateModified" , "" )),
54
+ "bibliography" : "paper.bib" ,
55
55
}
56
56
57
57
@@ -61,14 +61,14 @@ def make_date(date):
61
61
# yaml.allow_unicode = True
62
62
# yaml.indent(sequence=4, offset=2, mapping=4)
63
63
def dump (data , dest ):
64
- # yaml.dump(data, dest)
65
- ruamel .yaml .dump (
66
- data ,
67
- dest ,
68
- explicit_start = True ,
69
- allow_unicode = True ,
70
- Dumper = ruamel .yaml .RoundTripDumper
71
- )
64
+ # yaml.dump(data, dest)
65
+ ruamel .yaml .dump (
66
+ data ,
67
+ dest ,
68
+ explicit_start = True ,
69
+ allow_unicode = True ,
70
+ Dumper = ruamel .yaml .RoundTripDumper ,
71
+ )
72
72
73
73
74
74
dest = sys .stdout
0 commit comments