def __init__(self, cfr_title, cfr_part, doc_number): self.cfr_title = cfr_title self.cfr_part = cfr_part self.doc_number = doc_number self.writer = api_writer.Client() self.notices = fetch_notices(self.cfr_title, self.cfr_part, only_final=True) modify_effective_dates(self.notices) # Only care about final self.notices = [n for n in self.notices if 'effective_on' in n] self.eff_notices = group_by_eff_date(self.notices)
def test_fetch_notices(self, build_note): self.expect_json_http({"results": [{"some": "thing"}, {"another": "thing"}]}) build_note.return_value = ['NOTICE!'] notices = federalregister.fetch_notices(23, 1222) params = self.last_http_params() self.assertEqual(params['conditions[cfr][title]'], ['23']) self.assertEqual(params['conditions[cfr][part]'], ['1222']) self.assertEqual(['NOTICE!', 'NOTICE!'], notices)
def test_fetch_notices(self, build_note, requests): requests.get.return_value.json.return_value = { "results": [{"some": "thing"}, {"another": "thing"}]} build_note.return_value = ['NOTICE!'] notices = federalregister.fetch_notices(23, 1222) params = requests.get.call_args[1]['params'] self.assertTrue(23 in params.values()) self.assertTrue(1222 in params.values()) self.assertEqual(['NOTICE!', 'NOTICE!'], notices)
def test_fetch_notices(self, build_note): self.expect_json_http( {"results": [{ "some": "thing" }, { "another": "thing" }]}) build_note.return_value = ['NOTICE!'] notices = federalregister.fetch_notices(23, 1222) params = self.last_http_params() self.assertEqual(params['conditions[cfr][title]'], ['23']) self.assertEqual(params['conditions[cfr][part]'], ['1222']) self.assertEqual(['NOTICE!', 'NOTICE!'], notices)
def test_fetch_notices(self, build_note, requests): requests.get.return_value.json.return_value = { "results": [{ "some": "thing" }, { "another": "thing" }] } build_note.return_value = ['NOTICE!'] notices = federalregister.fetch_notices(23, 1222) params = requests.get.call_args[1]['params'] self.assertTrue(23 in params.values()) self.assertTrue(1222 in params.values()) self.assertEqual(['NOTICE!', 'NOTICE!'], notices)
def notices_for_cfr_part(title, part): """Retrieves all final notices for a title-part pair, orders them, and returns them as a dict[effective_date_str] -> list(notices)""" notices = fetch_notices(title, part, only_final=True) modify_effective_dates(notices) return group_by_eff_date(notices)
writer = api_writer.Client() with codecs.open(sys.argv[1], encoding='utf-8') as f: reg = unicode(f.read()) # First, the regulation tree reg_tree = build_whole_regtree(reg) cfr_part = reg_tree.label_id() cfr_title = sys.argv[2] doc_number = sys.argv[3] # Hold off on writing the regulation until after we know we have a valid # doc number # Next, notices notices = fetch_notices(cfr_title, cfr_part) modify_effective_dates(notices) notices = applicable_notices(notices, doc_number) # Didn't include the provided version if not notices: print "Could not find notice_doc_#, %s" % doc_number exit() for notice in notices: # No need to carry this around del notice['meta'] writer.notice(notice['document_number']).write(notice) writer.regulation(cfr_part, doc_number).write(reg_tree) # Finally, all the layers layer = external_citations.ExternalCitationParser(