-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_site.py
91 lines (79 loc) · 2.4 KB
/
build_site.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
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
import sys, os, subprocess, shutil
import rispy
subprocess.run(['mkdocs', 'build','--clean'])
shutil.copyfile('site/articles/index.html','site/articles/old.html')
#
# Transform RIS file to html
#
filepath = "molgw_biblio.ris"
with open(filepath, 'r') as bibliography_file:
entries = rispy.load(bibliography_file)
print("{} entries found in the RIS file".format(len(entries)))
fhtml = open('out.html','w')
fhtml.write("<ol reversed>\n\n")
for entry in entries:
#debug
#for k in entry.keys():
# print(k,entry[k])
string = ' <li>\n '
try:
authors = entry['first_authors'] + entry['authors']
except:
authors = entry['authors']
for i,author in enumerate(authors):
last_name = author.split(',')[0]
first_names = author.split(',')[1]
initials = ''
for n in first_names.split(" "):
if len(n) > 0:
initials += n[0] + '. '
#if i == len(entry['authors'])-1:
# string += initials + last_name + " "
#else:
# string += initials + last_name + ", "
string += initials + last_name + ", "
try:
string += entry['journal_name']
except:
try:
string += entry['alternate_title2']
except:
string += entry['secondary_title']
if 'volume' in entry.keys():
string += " <b>" + entry['volume'] + "</b>, "
if 'start_page' in entry.keys():
string += entry['start_page']
year = entry['year'].split("/")[0]
string += " (" + year + "). <br>\n"
if 'urls' in entry.keys():
string += f" <a href={entry['urls'][0]}>"
try:
string += entry['primary_title'] + "</a>\n"
except:
string += entry['title'] + "</a>\n"
string += " </li>\n\n"
#print(string)
fhtml.write(string)
#fhtml.write("</ol>\n")
fhtml.close()
#
# Merge the two html files for mkdocs and from rispy
#
f = open('site/articles/old.html','r')
fnew = open('site/articles/index.html','w')
for line in f:
if 'List to be filled here' not in line:
fnew.write(line)
else:
f2 = open('out.html','r')
for line2 in f2:
fnew.write(line2)
f2.close()
f2 = open('articles.html','r')
for line2 in f2:
fnew.write(line2)
f2.close()
f.close()
fnew.close()
os.remove('site/articles/old.html')
os.remove('out.html')