-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_shelat_keys.py
More file actions
92 lines (72 loc) · 2.54 KB
/
fix_shelat_keys.py
File metadata and controls
92 lines (72 loc) · 2.54 KB
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
91
92
#!/usr/bin/env python3
"""
This script needs to be run in the root folder containing the
folders "lib" and "db"
"""
import collections
import sys
import os
scriptdir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(scriptdir, "..", "lib"))
sys.path.append(os.path.join(scriptdir, "..", "db"))
sys.path.append(os.path.join(scriptdir, "..", "import"))
import mybibtex.parser
import mybibtex.database
from mybibtex.database import EntryKey, BibliographyData
import mybibtex.generator
import confs_years
import argparse
import logging
import re
import shutil
import time
from pybtex.bibtex.utils import split_name_list
import config
from config import *
mybibtex.generator.config = config
logging.basicConfig(level=logging.DEBUG)
color_texts = {
"Error": "\x1b[6;30;41mError\x1b[0m",
"Warning": "\x1b[6;30;43mWarning\x1b[0m",
"Success": "\x1b[6;30;42mSuccess\x1b[0m",
}
# Capture the author part of a key, between the ":" and the year
re_author_part_key = re.compile(r"^[a-zA-Z0-9]+:([a-zA-Z]+)[0-9]{2}[a-z]?$")
def fix_shelat_keys(args):
"""
Fix papers with author \"shelat\" whose keys got mangled
and used "ash" instead of "she"
"""
parser = mybibtex.parser.Parser()
parser.parse_file("db/abbrev0.bib")
parser.parse_file("db/crypto_db.bib")
db = parser.parse_file("db/crypto_conf_list.bib")
new_db = BibliographyData()
conf_years = confs_years.get_confs_years_inter(db, confs_missing_years)
for bib_key, entry in db.entries.items():
if "author" in entry.fields and "shelat" in entry.fields["author"].expand():
# paper with abhi shelat
new_bib_key = bib_key
if "ash" in str(bib_key):
# fixing the key
new_bib_key = EntryKey.from_string(str(bib_key).replace("ash", "she"))
new_db.add_entry(new_bib_key, entry)
else:
new_db.add_entry(bib_key, entry)
with open("db/crypto_db.bib", "w") as out:
out.write("% FILE GENERATED by add.py\n")
out.write("% DO NOT MODIFY MANUALLY\n")
out.write("\n")
out.write("\n")
for conf in sorted(conf_years.keys()):
(start, end) = conf_years[conf]
out.write("% {}:{}{} - {}\n".format(conf, " "*(16-len(conf)-1), start, end))
out.write("\n")
out.write("\n")
mybibtex.generator.bibtex_gen(out, new_db)
def main():
parser = argparse.ArgumentParser(fix_shelat_keys.__doc__)
args = parser.parse_args()
fix_shelat_keys(args)
if __name__ == "__main__":
main()