Hello all,
I've built a script that reaches out to the
govinfo.gov API to grab "all the Congressional publications released today" in XML format. The XML data for each record is then combed for specific elements, which are placed into a list of Field objects for that publication, and then that list of Field objects is "add_ordered_field"ed into a Record object which is then written to a MARC file.
[background]
The script will need to handle publications from one of eight different document collections, so I've got a base metaclass, "Collections", then a subclass for the major collection type, and then a variety of subclasses for each type of document within that particular document collection. The basic structure looks something like this:
Collections (base metaclass)
Senate hearings
Joint hearings
CRPT (reports)
House reports
Senate reports
Senate Executive reports
And so on...
[/background]
My main problem is that I'm getting an IndexError when the system tries to write the records to file ("list index out of range"). In debugging the problem, I noticed that when the system builds the list of Field objects, the control fields are always marked as though something went wrong in the subfield indicators, even though I'm calling them correctly via the "data" element. BTW, I'm using VSCode, hence the debugger image:

Here's that code building the list of Field objects (or the start of it, at least):
def base_fields(self):
base_list = [
Field(tag="006", data="m o d f "),
Field(tag="007", data="cr"),
Field(tag="008", data=self.date_008()),
Field(.....
I'm adding about 20 Fields to each record (it will vary according to the needs of the particular document class) with the following bit of code:
@abstractmethod
def build_record(self):
self.marc = Record()
for b in self.base_list:
self.marc.add_ordered_field(b)
for s in self.spec_list:
self.marc.add_ordered_field(s)
self.marc.leader.type_of_record = "a"
self.marc.leader.bibliographic_level = "m"
self.marc.leader.coding_scheme = "a"
self.marc.leader.encoding_level = " "
self.marc.leader.cataloging_form = "i"
return self
Is there a reason those control fields are marked as having an error? Note that the 024 field at the bottom of the first image doesn't seem concerned about the subfield indicators.
Is it my metaclass--subclass--subsubclass the issue? Is it the way the fields are being built? Any help is absolutely appreciated (despite what feels like spaghetti code at this point).
Regards,
Ben