1- from billparser .transformer import Session
1+ from billparser .db . handler import Session
22from billparser .translater import translate_paragraph
33
4- from billparser .db .models import ContentDiff , Section , Content
4+ from billparser .db .models import USCContentDiff , USCSection , USCContent
55
66from billparser .actions import ActionObject
77
@@ -24,6 +24,7 @@ def recursive_content(
2424 version_id : int ,
2525 last_ident : str ,
2626 session : "Session" ,
27+ legislation_id : int ,
2728) -> None :
2829 """
2930 This is the function that "inserts" a new block of content from a bill.
@@ -67,10 +68,10 @@ def recursive_content(
6768 " " .join (content_elem .itertext ()).strip ().replace ("\n " , " " )
6869 )
6970 if "heading" in heading .tag :
70- content = Content (
71+ content = USCContent (
7172 content_type = search_element .tag ,
7273 usc_ident = ident ,
73- section_id = section_id ,
74+ usc_section_id = section_id ,
7475 parent_id = content_id ,
7576 order_number = order ,
7677 version_id = version_id ,
@@ -86,27 +87,28 @@ def recursive_content(
8687 content_str = (
8788 " " .join (content_elem .itertext ()).strip ().replace ("\n " , " " )
8889 )
89- content = Content (
90+ content = USCContent (
9091 content_type = search_element .tag ,
9192 usc_ident = ident ,
92- section_id = section_id ,
93+ usc_section_id = section_id ,
9394 parent_id = content_id ,
9495 order_number = order ,
9596 version_id = version_id ,
9697 )
9798 session .add (content )
9899 session .flush ()
99- diff = ContentDiff (
100- chapter_id = chapter_id ,
100+ diff = USCContentDiff (
101+ usc_chapter_id = chapter_id ,
101102 version_id = version_id ,
102- content_id = content .content_id ,
103- section_id = section_id ,
103+ usc_content_id = content .usc_content_id ,
104+ usc_section_id = section_id ,
104105 number = enum .attrib .get ("value" , "" ),
105106 section_display = enum .text ,
106107 content_str = content_str ,
107108 heading = heading .text
108109 if heading is not None and heading .text != content_str
109110 else None ,
111+ legislation_content_id = legislation_id ,
110112 )
111113 session .add (diff )
112114 session .commit ()
@@ -116,12 +118,13 @@ def recursive_content(
116118 recursive_content (
117119 chapter_id ,
118120 section_id ,
119- content .content_id ,
121+ content .usc_content_id ,
120122 elem ,
121123 order ,
122124 version_id ,
123125 ident ,
124126 session ,
127+ legislation_id ,
125128 )
126129 order = order + 1
127130
@@ -135,24 +138,30 @@ def insert_section_after(action_obj: ActionObject, session: "Session") -> None:
135138 session (Session): DB session to insert into
136139 """
137140 cited_content = action_obj .cited_content
141+ legislation_content = action_obj .legislation_content
142+ if legislation_content is not None :
143+ legislation_id = legislation_content .legislation_content_id
144+ else :
145+ legislation_id = None
138146 new_vers_id = action_obj .version_id
139147 if action_obj .next is not None :
140148 chapter = (
141- session .query (Section )
142- .filter (Section . section_id == cited_content .section_id )
149+ session .query (USCSection )
150+ .filter (USCSection . usc_section_id == cited_content .usc_section_id )
143151 .all ()
144152 )
145153 if len (chapter ) > 0 :
146- chapter_id = chapter [0 ].chapter_id
154+ chapter_id = chapter [0 ].usc_chapter_id
147155 recursive_content (
148156 chapter_id ,
149- cited_content .section_id ,
157+ cited_content .usc_section_id ,
150158 cited_content .parent_id ,
151159 translate_paragraph (action_obj .next )[0 ],
152160 cited_content .order_number + 1 ,
153161 new_vers_id ,
154162 "/" .join (cited_content .usc_ident .split ("/" )[:- 1 ]),
155163 session ,
164+ legislation_id ,
156165 )
157166 session .commit ()
158167
@@ -169,9 +178,9 @@ def insert_end(action_obj: ActionObject, session: "Session") -> None:
169178 cited_content = action_obj .cited_content
170179 if action_obj .next is not None :
171180 last_content = (
172- session .query (Content )
173- .filter (Content .parent_id == cited_content .content_id )
174- .order_by (Content .order_number .desc ())
181+ session .query (USCContent )
182+ .filter (USCContent .parent_id == cited_content .usc_content_id )
183+ .order_by (USCContent .order_number .desc ())
175184 .limit (1 )
176185 .all ()
177186 )
@@ -193,43 +202,50 @@ def insert_text_end(action_obj: ActionObject, session: "Session") -> None:
193202 """
194203 action = action_obj .action
195204 cited_content = action_obj .cited_content
196- log .debug (cited_content .content_id )
205+ log .debug (cited_content .usc_content_id )
197206 new_vers_id = action_obj .version_id
198207 to_replace = action .get ("to_replace" , "" )
199208 chapter = (
200- session .query (Section )
201- .filter (Section . section_id == cited_content .section_id )
209+ session .query (USCSection )
210+ .filter (USCSection . usc_section_id == cited_content .usc_section_id )
202211 .limit (1 )
203212 .all ()
204213 )
205214 diff = None
215+ legislation_content = action_obj .legislation_content
216+ if legislation_content is not None :
217+ legislation_id = legislation_content .legislation_content_id
218+ else :
219+ legislation_id = None
206220 if len (chapter ) > 0 :
207- chapter_id = chapter [0 ].chapter_id
221+ chapter_id = chapter [0 ].usc_chapter_id
208222 if cited_content .heading is not None :
209223 heading_diff = cited_content .heading + " " + to_replace
210- if heading_diff != cited_content .heading :
211- diff = ContentDiff (
212- content_id = cited_content .content_id ,
213- section_id = cited_content .section_id ,
214- chapter_id = chapter_id ,
224+ if heading_diff != cited_content .heading and heading_diff != " " :
225+ diff = USCContentDiff (
226+ usc_content_id = cited_content .usc_content_id ,
227+ usc_section_id = cited_content .usc_section_id ,
228+ usc_chapter_id = chapter_id ,
215229 version_id = new_vers_id ,
216230 heading = heading_diff ,
231+ legislation_content_id = legislation_id ,
217232 )
218233 elif cited_content .content_str is not None :
219234 content_diff = cited_content .content_str + " " + to_replace
220- if content_diff != cited_content .content_str :
221- diff = ContentDiff (
222- content_id = cited_content .content_id ,
223- section_id = cited_content .section_id ,
224- chapter_id = chapter_id ,
235+ if content_diff != cited_content .content_str and heading_diff != " " :
236+ diff = USCContentDiff (
237+ usc_content_id = cited_content .usc_content_id ,
238+ usc_section_id = cited_content .usc_section_id ,
239+ usc_chapter_id = chapter_id ,
225240 version_id = new_vers_id ,
226241 content_str = content_diff ,
242+ legislation_content_id = legislation_id ,
227243 )
228244 if diff is not None :
229245 log .debug ("adding" )
230246 session .add (diff )
231247 session .commit ()
232- log .debug ("Added diff" , diff .diff_id )
248+ log .debug ("Added diff" , diff .usd_content_diff_id )
233249
234250
235251def insert_text_after (action_obj : ActionObject , session : "Session" ) -> None :
0 commit comments