|
8 | 8 | from bibtexparser.bwriter import BibTexWriter |
9 | 9 | from requests.exceptions import RequestException |
10 | 10 |
|
11 | | - |
12 | | -def normalize_month_fields(bib): |
13 | | - def replace_month(match): |
14 | | - prefix, value = match.groups() |
15 | | - value = unescape(value).strip() |
16 | | - if value.startswith("{") and value.endswith("}"): |
17 | | - return match.group(0) |
18 | | - if value.startswith('"') and value.endswith('"'): |
19 | | - value = value[1:-1].strip() |
20 | | - value = value.strip("'\"{}") |
21 | | - value = re.sub(r"[^A-Za-z]", "", value) |
22 | | - return f"{prefix}{{{value}}}," |
23 | | - |
24 | | - return re.sub( |
25 | | - r"(^\s*month\s*=\s*)([^,\n]+)\s*,", |
26 | | - replace_month, |
27 | | - bib, |
28 | | - flags=re.MULTILINE | re.IGNORECASE, |
29 | | - ) |
30 | | - |
| 11 | +from utils import fixBadBibFormat |
31 | 12 |
|
32 | 13 | def fetch_doi_content(url, accept_header, description): |
33 | 14 | try: |
@@ -104,7 +85,7 @@ def fetch_doi_content(url, accept_header, description): |
104 | 85 | if id != id_db: |
105 | 86 | print(f'Note: ID updated from {id_db} to {id} to reflect the publication year.') |
106 | 87 | bib = "{".join([bType] + [','.join([id]+rest2)] + rest1[1:]) |
107 | | - bib = normalize_month_fields(bib) |
| 88 | + bib = fixBadBibFormat(bib) |
108 | 89 | bib_db = bibtexparser.loads(bib) |
109 | 90 | new_entries = bib_db.get_entry_list() |
110 | 91 | if not new_entries: |
|
0 commit comments