-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbibtex-compatibility.py
executable file
·60 lines (55 loc) · 1.92 KB
/
bibtex-compatibility.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
# Original author: Jon Sterling
# Original source: https://github.com/jonsterling/bibtex-references
# Modified by Kartik for use in qpl-bib
import re
import sys
month_names = {
1: "jan",
2: "feb",
3: "mar",
4: "apr",
5: "may",
6: "jun",
7: "jul",
8: "aug",
9: "sep",
10: "oct",
11: "nov",
12: "dec"
}
db_name = sys.argv[1]
old_db = open(db_name + ".bib","r")
new_db = open("bibtex.bib","w")
for line in old_db.readlines():
date_pattern = re.search(r"date.*{(\d+)-?(\d+)?.*}",line)
if date_pattern:
new_db.write(" year = {{{0:s}}},\n".format(date_pattern.group(1)))
# print " year = {{{0:s}}},\n".format(date_pattern.group(1)),
if date_pattern.group(2) is not None:
month = month_names[int(date_pattern.group(2))];
new_db.write(" month = {},\n".format(month))
elif re.search("journaltitle",line):
new_db.write(line.replace("journaltitle","journal"))
elif re.search("location",line):
new_db.write(line.replace("location","address"))
elif re.search("eprinttype",line):
new_db.write(line.replace("eprinttype","archiveprefix"))
# the following change is not suitable for techreports
# elif re.search("institution",line):
# new_db.write(line.replace("institution","school"))
elif re.search("@online",line):
new_db.write(line.replace("@online","@unpublished"))
elif re.search("@report",line):
new_db.write(line.replace("@report","@techreport"))
elif re.search("@inbook",line):
new_db.write(line.replace("@inbook","@incollection"))
elif re.search("@collection",line):
new_db.write(line.replace("@collection","@book"))
elif re.search("@thesis{Singhal2020",line):
new_db.write(line.replace("@thesis","@mastersthesis"))
elif re.search("@thesis",line):
new_db.write(line.replace("@thesis","@phdthesis"))
else:
new_db.write(line)
old_db.close()
new_db.close()