Skip to content

Some months are different #1

@yaronf

Description

@yaronf

Thanks for the package. It works nicely for me with a variety of bibtex entries from various sources, except for one issue. Some entries have the month field as "November" or "{November}" (rather than "nov"), which crashes the code. Quick patch below.

diff --git a/bibtex.py b/bibtex.py
index 26da38d..e7cc4c3 100644
--- a/bibtex.py
+++ b/bibtex.py
@@ -21,7 +21,20 @@ BIBTEX_MONTHS = {
     "sep": 9,
     "oct": 10,
     "nov": 11,
-    "dec": 12}
+    "dec": 12,
+    "January": 1,
+    "February": 2,
+    "March": 3,
+    "April": 4,
+    "May": 5,
+    "June": 6,
+    "July": 7,
+    "August": 8,
+    "September": 9,
+    "October": 10,
+    "November": 11,
+    "December": 12,
+}

 # For testing convenience
 EXAMPLE_STRING = """@ARTICLE{2012PhRvD..85d4027A,
@@ -61,7 +74,7 @@ class BibtexRecord():
             ty = self.typemap.get(k, -1)
             x = _bibtex.expand(context, items[k], ty)
             if k == "month":
-                month = BIBTEX_MONTHS[_bibtex.get_native(items[k])]
+                month = BIBTEX_MONTHS[self._strip_braces(_bibtex.get_native(items[k]))]
                 self.date[0] = month
                 self.data["month"] = month
                 continue
@@ -69,6 +82,13 @@ class BibtexRecord():
             self.data[k] = self.build(ty, x)
         self.date[1] = self.data["year"]

+    def _strip_braces(self, s):
+        if s[0] == '{' and s[-1:] == '}':
+            return s[1:-1]
+        else:
+            return s
+
+
     def _build_author(self, t):
         names, honorifics, lineage, last = [], [], [], ''
         if t[0]: honorifics = [t[0]] # Prof, doctor, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions