def test_meta_data_passes_fields(self): """If a fields param is provided, it should be sent""" self.expect_json_http({"some": "value"}, uri=re.compile(".*/articles/1234-56")) federalregister.meta_data("1234-56", ['field1', 'field2', 'field3']) params = self.last_http_params() self.assertEqual(params['fields[]'], ['field1', 'field2', 'field3'])
def test_meta_data_okay(self): """Successfully returns the appropriate JSON""" self.expect_json_http({"some": "value"}, uri=re.compile(".*/articles/1234-56")) self.assertEqual({"some": "value"}, federalregister.meta_data("1234-56"))
def preprocess_notice(document_number): """Preprocess notice XML. Either fetch from the Federal Register or read a notice from disk. Apply some common transformations to it and output the resulting file(s). There may be more than one as documents might be split if they have multiple effective dates.""" meta = federalregister.meta_data( document_number, ["effective_on", "full_text_xml_url", "publication_date", "volume"] ) notice_xmls = list(notice_xmls_for_url(document_number, meta["full_text_xml_url"])) deps = dependency.Graph() for notice_xml in notice_xmls: file_name = document_number notice_xml.published = meta["publication_date"] notice_xml.fr_volume = meta["volume"] if len(notice_xmls) > 1: effective_date = notice_xml.derive_effective_date() file_name = split_doc_num(document_number, effective_date.isoformat()) elif meta.get("effective_on"): notice_xml.effective = meta["effective_on"] else: notice_xml.derive_effective_date() notice_xml.version_id = file_name notice_entry = entry.Notice(file_name) notice_entry.write(notice_xml) if notice_xml.source_is_local: deps.add(str(notice_entry), notice_xml.source)
def preprocess_notice(document_number): """Preprocess notice XML. Either fetch from the Federal Register or read a notice from disk. Apply some common transformations to it and output the resulting file(s). There may be more than one as documents might be split if they have multiple effective dates.""" meta = federalregister.meta_data( document_number, [ "agencies", "docket_ids", "effective_on", "cfr_references", "comments_close_on", "full_text_xml_url", "html_url", "publication_date", "regulation_id_numbers", "volume" ]) notice_xmls = list(notice_xmls_for_url(document_number, meta['full_text_xml_url'])) deps = dependency.Graph() for notice_xml in notice_xmls: notice_xml.published = meta['publication_date'] notice_xml.fr_volume = meta['volume'] if meta.get('html_url'): notice_xml.fr_html_url = meta['html_url'] if meta.get("comments_close_on"): notice_xml.comments_close_on = meta["comments_close_on"] if meta.get('regulation_id_numbers'): notice_xml.rins = meta['regulation_id_numbers'] if meta.get('docket_ids'): notice_xml.docket_ids = meta['docket_ids'] notice_xml.set_agencies(meta.get('agencies', [])) cfr_refs = convert_cfr_refs(meta.get('cfr_references', [])) if cfr_refs: notice_xml.cfr_refs = cfr_refs file_name = document_number if len(notice_xmls) > 1: effective_date = notice_xml.derive_effective_date() file_name = split_doc_num(document_number, effective_date.isoformat()) elif meta.get('effective_on'): notice_xml.effective = meta['effective_on'] notice_xml.version_id = file_name notice_xml.derive_where_needed() notice_entry = entry.Notice(file_name) notice_entry.write(notice_xml) if notice_xml.source_is_local: deps.add(str(notice_entry), notice_xml.source)
def fetch_sxs(document_number): """Fetch and parse Section-by-Section analyses. DOCUMENT_NUMBER is the identifier associated with a final rule. If a rule has been split, use the split identifiers, a.k.a. version ids""" sxs_entry = entry.SxS(document_number) notice_entry = entry.Notice(document_number) deps = dependency.Graph() deps.add(sxs_entry, notice_entry) deps.validate_for(sxs_entry) # We don't check for staleness as we want to always execute when given a # specific file to process # @todo - break apart processing of SxS. We don't need all of the other # fields notice_xml = notice_entry.read() notice_meta = meta_data(document_number, FULL_NOTICE_FIELDS) notice = build_notice(notice_xml.cfr_refs[0].title, None, notice_meta, xml_to_process=notice_xml.xml)[0] sxs_entry.write(notice)
def fetch_sxs(document_number): """Fetch and parse Section-by-Section analyses. DOCUMENT_NUMBER is the identifier associated with a final rule. If a rule has been split, use the split identifiers, a.k.a. version ids""" sxs_entry = entry.SxS(document_number) notice_entry = entry.Notice(document_number) deps = dependency.Graph() deps.add(sxs_entry, notice_entry) deps.validate_for(sxs_entry) # We don't check for staleness as we want to always execute when given a # specific file to process # @todo - break apart processing of SxS. We don't need all of the other # fields notice_xml = notice_entry.read() notice_meta = meta_data(document_number, FULL_NOTICE_FIELDS) notice = build_notice(notice_xml.cfr_titles[0], None, notice_meta, xml_to_process=notice_xml.xml)[0] sxs_entry.write(notice)