Skip to content

Commit 20ff6e6

Browse files
committed
deploy: 23c65a6
1 parent 560a9a6 commit 20ff6e6

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

bin/issue_to_bibtex.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import argparse
2-
import re
3-
import requests
42
import fileinput
3+
from html import unescape
4+
import re
55
import urllib
6+
import requests
67

78
from arxivcheck.arxiv import get_arxiv_info
89

@@ -11,6 +12,26 @@
1112
from bibtexparser.bwriter import BibTexWriter
1213

1314

15+
def normalize_month_fields(bib):
16+
def replace_month(match):
17+
prefix, value = match.groups()
18+
value = unescape(value).strip()
19+
if value.startswith("{") and value.endswith("}"):
20+
return match.group(0)
21+
if value.startswith('"') and value.endswith('"'):
22+
value = value[1:-1].strip()
23+
value = value.strip("'\"{}")
24+
value = re.sub(r"[^A-Za-z]", "", value)
25+
return f"{prefix}{{{value}}},"
26+
27+
return re.sub(
28+
r"(^\s*month\s*=\s*)([^,\n]+)\s*,",
29+
replace_month,
30+
bib,
31+
flags=re.MULTILINE | re.IGNORECASE,
32+
)
33+
34+
1435
try:
1536

1637
parser = argparse.ArgumentParser()
@@ -149,12 +170,7 @@
149170
bib = re.sub(r'(@[a-z]*{)(.*?),', r'\1' + id + ',', bib)
150171
url_bad = re.search(r'url\s*=\s*{(.*)}', bib).groups()[0]
151172
bib = re.sub(r'(url\s*=\s*{)(.*)}', r'\1' + urllib.parse.unquote(url_bad) + '}', bib)
152-
bib = re.sub(
153-
r'(^\s*month\s*=\s*)(?:[\'"]?)([A-Za-z]+)(?:[\'"]?)\s*,',
154-
r'\1{\2},',
155-
bib,
156-
flags=re.MULTILINE,
157-
)
173+
bib = normalize_month_fields(bib)
158174
bib_db = bibtexparser.loads(bib)
159175
print(bib)
160176
else:

0 commit comments

Comments
 (0)