/
us_bills.py
1198 lines (1040 loc) · 40.3 KB
/
us_bills.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re, datetime
from lxml import etree
from lxml.html import fragment_fromstring
import os, os.path
from util import download, warn, md5_base64, format_datetime
from names import parse_name
thomas_bill_type_codes = (('HC', 'hc'), ('HE', 'hr'), ('HJ', 'hj'), ('HR', 'h'), ('HZ', 'hz'), ('SC', 'sc'), ('SE', 'sr'), ('SJ', 'sj'), ('SN', 's'), ('SP', 'sp'))
def update_bills(congress, force_update):
"""Scans THOMAS search results for the indicated Congress updating bill
XML data (bills/*.xml) for any changed records. Or re-parses all files if
force_update == True."""
# Make the output directory.
try:
os.makedirs("../data/us/%d" % congress)
except:
pass
# Store md5sums of the search result records in this file to detect changes.
# Load in the contents of the file.
changefile = ("../data/us/%d/bills.bsshash" % congress);
changehash = {}
if os.path.exists(changefile):
with open(changefile, "r") as fchanges:
for line in fchanges:
bill_code, status_hash = line.strip().split(" ")
changehash[bill_code] = status_hash
newchangehash = {} # store new hashes to write here
# Load results for each bill type (and two amendment types).
for tbt, bt in thomas_bill_type_codes:
# Loop through the paginated responses.
lastseq = None
offset = 0
rec = None
while True:
# download file
url = "http://thomas.loc.gov/cgi-bin/bdquery/d?d%03d:%d:./list/bss/d%03d%s.lst:[[o]]" \
% (congress, offset, congress, tbt)
content, mtime = download(url)
if not content:
warn("Failed to download %s" % url)
break
# Read file by line, grouping lines together into "rec" until we hit an <hr>, at which point
# we handle the record.
for line in content.split("\n"):
hr = line.find("<hr")
if hr >= 0 and rec != None:
# process the record ending here
rec += line[0:hr]
update_bills_2(congress, bt, bn, rec, changehash, newchangehash, force_update)
rec = None
# check if a record begins here
m = re.search(r'<b>\s*(\d+)\.</b> <a href="/cgi-bin/bdquery/d\?d\d+:\d+:./list/bss/d\d+[a-z]+.lst::">\s*[a-z\.]+(\d+)\s*</a>(: )?(.*)', line.lower())
if m != None:
# if we have an open record, process it; shouldn't occur since records end on <hr>'s.
if rec != None:
update_bills_2(congress, bt, bn, rec, changehash, newchangehash, force_update)
seq = int(m.group(1)) # index in the search result
bn = int(m.group(2)) # bill number
rec = m.group(4) + "\n" # start record with the rest of the text on the line
# check that we didn't miss a record
if lastseq != None and lastseq != seq-1:
warn("Skipped a sequence number %d to %d." % (lastseq, seq))
lastseq = seq
# add line to existing record
elif rec != None:
rec += line + "\n"
# check if there are more results (i.e. continue onto next page)
elif "&\">NEXT PAGE" in line and lastseq != None:
offset = lastseq
# if we hit a NEXT PAGE, continue the loop
if lastseq == None or offset < lastseq:
break
if lastseq == None:
warn("No %s bills" % tbt)
# If there was an open record when we ended, process it, but it shouldn't happen.
if rec != None:
update_bills_2(congress, bt, bn, rec, changehash, newchangehash, force_update)
# Write out current record md5s to the hash file.
with open(changefile, "w") as fchanges:
items = sorted(newchangehash.items())
for item in items:
fchanges.write("%s %s\n" % item)
def update_bills_2(congress, bill_type, bill_number, recordtext, changehash, newchangehash, force_update):
"""Compares a THOMAS search result record to the hash file to see if anything
changed, and if so, or if force_update == True, re-parses the bill or amendment."""
key = bill_type + str(bill_number)
rec = md5_base64(recordtext)
if not force_update and key in changehash and changehash[key] == rec:
newchangehash[key] = changehash[key]
return
if not force_update:
warn("Detected Update to %d %s %d." % (congress, bill_type, bill_number))
try:
if bill_type == 'hz':
#if (!ParseAmendment($bs, 'h', 'Z', $bn)) { return; }
pass
elif bill_type == 'sp':
#if (!ParseAmendment($bs, 's', 'P', $bn)) { return; }
pass
else:
parse_bill(congress, bill_type, bill_number)
newchangehash[key] = rec
except Exception as e:
import traceback
warn("Parsing bill %d %s %d: " % (congress, bill_type, bill_number) + unicode(e) + "\n" + traceback.format_exc())
def parse_bill(congress, bill_type, bill_number):
"""Downloads and parses THOMAS bill status and summary files."""
# map our bill type code to the THOMAS bill type code (namely, hr is confused with H.R.
# so make it hres).
bill_type2 = bill_type
if bill_type2 == "hr": bill_type2 = "hres"
# Start with the All Actions page, from which we'll also grab basic metadata.
url = "http://thomas.loc.gov/cgi-bin/bdquery/z?d%03d:%s%s:@@@X" % (congress, bill_type2, bill_number)
content, mtime = download(url)
if not content:
raise Exception("Failed to download bill status page: " + url)
root = etree.Element("bill")
root.set("session", str(congress))
root.set("type", bill_type)
root.set("number", str(bill_number))
root.set("updated", format_datetime(mtime))
sponsor = None
introduced_date = None
title = None
actions = []
action_indentation = 0
state_name, state_date = None, None
for line in content.split("\n"):
# Match Sponsor line, which can be either No Sponsor or a name/state/district.
# Parse the name later, after we find the introduced date.
m = re.search(r"<b>Sponsor: </b>(No Sponsor|<a [^>]+>(.*)</a>\s+\[((\w\w)(-(\d+))?)\])", line, re.I)
if m != None:
if m.group(1) == "No Sponsor":
sponsor = (None, None, None, None)
else:
name = m.group(2)
if name.startswith("Sen "):
senrep = "sen"
name = name[4:]
elif name.startswith("Rep "):
senrep = "rep"
name = name[4:]
else:
raise Exception("Invalid name: missing title: " + name)
sponsor = (name, senrep, m.group(4), m.group(6)) # name, type, state, district
# Match the line giving the date of introduction.
m = re.search(r"\(introduced ([\d\/]+)\)", line, re.I)
if m != None:
introduced_date = datetime.datetime.strptime(m.group(1), "%m/%d/%Y").date()
state_name, state_date = ("INTRODUCED", introduced_date)
# Match the Title line, which we use 1) to check if this is a bill number reserved for the speaker,
# 2) for determining whether this is a proposal for a constitutional amendment for parsing
# vote status, and 3) as a backup in case the THOMAS Titles page cannot be parsed.
m = re.search(r"<B>(Latest )?Title:</B> (.+)", line, re.I)
if m != None:
title = m.group(2)
# Match action lines.
m = re.search(r"<dt><strong>([\d/ :apm]+):</strong><dd>(.+)", line, re.I)
if m != None:
# Indentation indicates committee action.
if line.startswith("<dl>"): action_indentation += 1
if line.startswith("</dl>"): action_indentation -= 1
text = re.sub(r"</?[Aa]( \S.*?)?>", "", m.group(2))
# The date can be either a date or a date and time.
try:
action_date = datetime.datetime.strptime(m.group(1), "%m/%d/%Y %I:%M%p")
except:
#print repr(m.group(1))
try:
action_date = datetime.datetime.strptime(m.group(1), "%m/%d/%Y").date()
except:
raise ValueError("Could not parse date: " + m.group(1))
# references are given in parentheses at the end
considerations = []
m = re.search("\s+\((.*)\)\s*$", text)
if m:
text = text[0:m.start()] + text[m.end():]
for con in m.group(1).split("; "):
if ": " not in con:
considerations.append( ("", con) )
else:
considerations.append( con.split(": ") )
# Parse the actual action line.
attrs = parse_bill_action(text, bill_type, state_name, title)
if "state" in attrs:
state_name, state_date = attrs["state"], action_date
actions.append((action_date, action_indentation, text, attrs, considerations))
if introduced_date == None:
raise Exception("No introduced date.")
if sponsor == None:
raise Exception("No sponsor line.")
elif sponsor[0] == None:
sponsor = 0
else:
sponsor = parse_name(sponsor[0], introduced_date, nameformat="lastfirst", role_type=sponsor[1], state=sponsor[2], district=sponsor[3])
if "Reserved for the" in title:
raise Exception("Skipping bill " + title.lower())
# Start building the XML
state = etree.Element("state")
state.set("datetime", format_datetime(state_date))
state.text = state_name
root.append(state)
intronode = etree.Element("introduced")
intronode.set("datetime", introduced_date.isoformat())
root.append(intronode)
if sponsor != 0:
sponsornode = etree.Element("sponsor")
sponsornode.set("id", str(sponsor))
root.append(sponsornode)
# Download and parse the cosponsors page.
cosponsors = etree.Element("cosponsors")
root.append(cosponsors)
url = url.replace("@@@X", "@@@P")
content, mtime = download(url)
if not content:
raise Exception("Failed to download cosponsors page: " + url)
content = re.sub(r"(\[[A-Z\d\-]+\])\n( - \d\d?\/)", lambda m : m.group(1) + m.group(2), content) # bring cosponsorship date onto previous line
content = re.sub(r"</br>", "\n", content)
for line in content.split("\n"):
m = re.search(r"(<br ?/>)?<a href=[^>]+>(Rep|Sen) (.+)</a> \[([A-Z\d\-]+)\] - (\d\d?/\d\d?/\d\d\d\d)(\(withdrawn - (\d\d?/\d\d?/\d\d\d\d)\))?", line, re.I)
if m:
title, name, state_district, join_date, withdrawn_date = m.group(2), m.group(3), m.group(4), m.group(5), m.group(7)
join_date = datetime.datetime.strptime(join_date, "%m/%d/%Y").date()
if withdrawn_date != None:
withdrawn_date = datetime.datetime.strptime(withdrawn_date, "%m/%d/%Y").date()
name = name.replace("Colordao", "Colorado") # typo
if not "-" in state_district:
state = state_district
district = None
else:
state, district = state_district.split("-")
person = parse_name(name, join_date, nameformat="lastfirst", role_type=title.lower(), state=state, district=district)
csp = etree.Element("cosponsor")
csp.set("id", str(person))
csp.set("joined", join_date.isoformat())
if withdrawn_date: csp.set("withdrawn", withdrawn_date.isoformat())
cosponsors.append(csp)
# Download and parse the titles page.
titles = etree.Element("titles")
root.append(titles)
url = url.replace("@@@P", "@@@T")
content, mtime = download(url)
if not content:
raise Exception("Failed to download titles page: " + url)
content = re.sub(r"(<I>)?(<br/>|<p>)", lambda m : "\n" + ("" if not m.group(1) else m.group(1)), content)
title_type, title_as = None, None
for line in content.split("\n"):
if line == "</ul>":
break
m = re.search(r"<li>(.*) title(\(s\))?( as ([\w ]*))?:", line, re.I)
if m:
title_type, title_as = m.group(1).lower(), m.group(4).lower()
elif title_type != None and line.strip() != "":
partial = False
if line.startswith("<I>"):
partial = True
line = line[3:]
line = line.replace("<I>", "")
line = line.replace("</I>", "")
line = line.replace(" (identified by CRS)", "")
t = etree.Element("title")
t.set("type", title_type)
t.set("as", title_as)
t.set("partial", "yes" if partial else "no")
t.text = line.strip()
titles.append(t)
if len(titles) == 0:
# Sometimes titles aren't available.
t = etree.Element("title")
t.set("type", "official")
t.set("as", "introduced")
t.set("partial", "no")
t.text = title
titles.append(t)
# Download and parse the committees page.
committees = etree.Element("committees")
root.append(committees)
url = url.replace("@@@T", "@@@C")
content, mtime = download(url)
if not content:
raise Exception("Failed to download committees page: " + url)
last_committee = None
for line in content.split("\n"):
m = re.search(r'<a href="/cgi-bin/bdquery(tr)?/R\?[^"]+">(.*)</a>\s*</td><td width="65\%">(.+)</td></tr>', line, re.I)
if m:
committee = m.group(2)
activity = m.group(3)
committee = re.sub(r"\s+", " ", committee).strip()
if not committee.startswith("Subcommittee on "):
last_committee = committee
committee = find_committee(committee, None, congress)
else:
committee = committee[len("Subcommittee on "):]
committee = find_committee(last_committee, committee, congress)
cx = etree.Element("committee")
cx.set("code", committee)
cx.set("activity", activity)
committees.append(cx)
# Download and parse related bills page.
related_bill_type_map = { }
for a, b in thomas_bill_type_codes:
related_bill_type_map[a] = b
related_bill_relationship_map = {
"Identical bill identified by CRS": "identical",
"Related bill identified by CRS": "related",
"Related bill as identified by the House Clerk's office": "related",
"passed in House in lieu of this bill": "supersedes",
"passed in Senate in lieu of this bill": "supersedes",
}
related_bills = etree.Element("relatedbills")
root.append(related_bills)
url = url.replace("@@@C", "@@@K")
content, mtime = download(url)
if not content:
raise Exception("Failed to download related bills page: " + url)
for line in content.split("\n"):
m = re.search(r'<a href="/cgi-bin/bdquery(tr)?/z\?d(\d\d\d):(\w+)(\d\d\d\d\d):">.*</a></td><td>(.*)</td></tr>', line, re.I)
if m:
related_bill_congress = int(m.group(2))
related_bill_type = related_bill_type_map[m.group(3)]
related_bill_number = int(m.group(4))
if re.search("Rule related to", m.group(5)):
related_bill_relationship = "rule"
else:
related_bill_relationship = related_bill_relationship_map[m.group(5)]
rb = etree.Element("bill")
rb.set("relation", related_bill_relationship)
rb.set("session", str(related_bill_congress))
rb.set("type", related_bill_type)
rb.set("number", str(related_bill_number))
related_bills.append(rb)
# Download and parse CRS subject terms page.
subjects = etree.Element("subjects")
root.append(subjects)
url = url.replace("@@@K", "@@@J")
content, mtime = download(url)
if not content:
raise Exception("Failed to download subject terms page: " + url)
for line in content.split("\n"):
m = re.search(r'<a href="/cgi-bin/bdquery/\?.*@FIELD\(FLD001.*\)">(.*)</a> ', line, re.I)
if m:
term = m.group(1)
term = re.sub(r"\s+", " ", term).strip()
s = etree.Element("term")
s.set("name", term)
subjects.append(s)
# Download and parse amendments page.
amendments = etree.Element("amendments")
root.append(amendments)
url = url.replace("@@@J", "@@@A")
content, mtime = download(url)
if not content:
raise Exception("Failed to download amendments page: " + url)
for m in re.finditer(r'<a href="/cgi-bin/bdquery/z\?d\d+:([HS])([ZP])(\d+):">[HS]\.AMDT\.\d+</a>', content, re.I):
amendment_chamber = m.group(1).lower()
amendment_number = int(m.group(3))
a = etree.Element("amendment")
a.set("number", amendment_chamber + str(amendment_number))
amendments.append(a)
# Put the actions in here.
actionsnode = etree.Element("actions")
root.append(actionsnode)
for adate, aindent, text, attrs, considerations in actions:
nodename = "action"
if "nodename" in attrs:
nodename = attrs["nodename"]
del attrs["nodename"]
node = etree.Element(nodename)
actionsnode.append(node)
node.set("datetime", format_datetime(adate))
for k, v in sorted(attrs.items()):
if v == None:
continue
node.set(k, v)
n = etree.Element("text")
n.text = text
node.append(n)
for c in considerations:
n = etree.Element("reference")
n.set("label", c[0])
n.set("ref", c[1])
node.append(n)
# Download the CRS summary text.
url = url.replace("@@@A", "@@@D&summ2=m&")
content, mtime = download(url)
if not content:
raise Exception("Failed to download summary page: " + url)
mode = 0
summary = ""
for line in content.split("\n"):
if mode == 1:
if "<hr" in line:
mode = 0
elif "THOMAS Home" in line or "id=\"footer\"" in line:
break
else:
line = re.sub(r"<a.*?>(.*?)</a>", lambda m : m.group(1), line, re.I)
summary += line + "\n"
elif "SUMMARY AS OF" in line:
mode = 1
summary = re.sub(r"\(There (is|are) \d+ other summar(y|ies)\)", "", summary, re.I)
root.append(fragment_fromstring(summary, create_parent="summary"))
try:
os.makedirs("../data/us/%d/bills" % congress)
except:
pass
return etree.tostring(root, pretty_print=True)
def parse_bill_action(line, bill_type, prev_state, title):
"""Parse a THOMAS bill action line. Returns attributes to be set in the XML file on the action line."""
attrs = { }
# If a line starts with an amendment number, this action is on the amendment and cannot
# be parsed yet.
m = re.match("r^(H|S)\.Amdt\.(\d+)", line, re.I)
if m != None:
# Process actions specific to amendments separately.
attrs["amendment"] = m.group(1).lower() + m.group(2)
# Otherwise, parse the action line for key actions.
else:
# A House Vote.
line = re.sub(", the Passed", ", Passed", line); # 106 h4733 and others
m = re.search(r"(On passage|On motion to suspend the rules and pass the bill|On motion to suspend the rules and agree to the resolution|On motion to suspend the rules and pass the resolution|On agreeing to the resolution|On agreeing to the conference report|Two-thirds of the Members present having voted in the affirmative the bill is passed,?|On motion that the House agree to the Senate amendments?|On motion that the House suspend the rules and concur in the Senate amendments?|On motion that the House suspend the rules and agree to the Senate amendments?|On motion that the House agree with an amendment to the Senate amendments?|House Agreed to Senate Amendments.*?|Passed House)(, the objections of the President to the contrary notwithstanding.?)?(, as amended| \(Amended\))? (Passed|Failed|Agreed to|Rejected)? ?(by voice vote|without objection|by (the Yeas and Nays|Yea-Nay Vote|recorded vote)((:)? \(2/3 required\))?: \d+ - \d+(, \d+ Present)? [ \)]*\((Roll no\.|Record Vote No:) \d+\))", line, re.I)
if m != None:
motion, isoverride, asamended, passfail, how = m.group(1), m.group(2), m.group(3), m.group(4), m.group(5)
if re.search(r"Passed House|House Agreed to", motion, re.I):
passfail = 'pass'
elif re.search(r"Pass|Agreed", passfail, re.I):
passfail = 'pass'
else:
passfail = 'fail'
if "Two-thirds of the Members present" in motion:
isoverride = True
if isoverride:
votetype = "override"
elif re.search(r"(agree (with an amendment )?to|concur in) the Senate amendment", line, re.I):
votetype = "pingpong"
elif re.search("conference report", line, re.I):
votetype = "conference"
elif bill_type[0] == "h":
votetype = "vote"
else:
votetype = "vote2"
roll = None
m = re.search(r"\((Roll no\.|Record Vote No:) (\d+)\)", how, re.I)
if m != None:
roll = m.group(2)
suspension = None
if roll and "On motion to suspend the rules" in motion:
suspension = True
attrs["nodename"] = "vote"
attrs["votetype"] = votetype
attrs["how"] = how
if roll:
attrs["roll"] = roll
# get the new state of the bill after this vote
new_state = get_vote_resulting_state(votetype, "h", passfail=="pass", bill_type, suspension, asamended, title, prev_state)
if new_state:
attrs["state"] = new_state
m = re.search(r"Passed House pursuant to", line, re.I)
if m != None:
votetype = "vote" if (bill_type[0] == "h") else "vote2"
attrs["nodename"] = "vote"
attrs["votetype"] = votetype
attrs["how"] = "by special rule"
# get the new state of the bill after this vote
new_state = get_vote_resulting_state(votetype, "h", passfail=="pass", bill_type, False, False, title, prev_state)
if new_state:
attrs["state"] = new_state
# A Senate Vote
m = re.search(r"(Passed Senate|Failed of passage in Senate|Resolution agreed to in Senate|Received in the Senate, considered, and agreed to|Submitted in the Senate, considered, and agreed to|Introduced in the Senate, read twice, considered, read the third time, and passed|Received in the Senate, read twice, considered, read the third time, and passed|Senate agreed to conference report|Cloture \S*\s?on the motion to proceed .*?not invoked in Senate|Cloture on the bill not invoked in Senate|Cloture on the bill invoked in Senate|Cloture on the motion to proceed to the bill invoked in Senate|Cloture on the motion to proceed to the bill not invoked in Senate|Senate agreed to House amendment|Senate concurred in the House amendment)(,?.*,?) (without objection|by Unanimous Consent|by Voice Vote|by Yea-Nay( Vote)?\. \d+\s*-\s*\d+\. Record Vote (No|Number): \d+)", line, re.I)
if m != None:
motion, extra, how = m.group(1), m.group(2), m.group(3)
roll = None
if re.search("passed|agreed|concurred|bill invoked", motion, re.I):
passfail = "pass"
else:
passfail = "fail"
votenodename = "vote"
if re.search("over veto", extra, re.I):
votetype = "override"
elif re.search("conference report", motion, re.I):
votetype = "conference"
elif re.search("cloture", motion, re.I):
votetype = "cloture"
votenodename = "vote-aux" # because it is not a vote on passage
elif re.search("Senate agreed to House amendment|Senate concurred in the House amendment", motion, re.I):
votetype = "pingpong"
elif bill_type[0] == "s":
votetype = "vote"
else:
votetype = "vote2"
m = re.search(r"Record Vote (No|Number): (\d+)", how, re.I)
if m != None:
roll = m.group(2)
how = "roll"
asamended = False
if re.search(r"with amendments|with an amendment", extra, re.I):
asamended = True
attrs["nodename"] = votenodename
attrs["votetype"] = votetype
attrs["how"] = how
if roll:
attrs["roll"] = roll
# get the new state of the bill after this vote
new_state = get_vote_resulting_state(votetype, "s", passfail=="pass", bill_type, False, asamended, title, prev_state)
if new_state:
attrs["state"] = new_state
# TODO: Make a new state for this as pre-reported.
m = re.search(r"Placed on (the )?([\w ]+) Calendar( under ([\w ]+))?[,\.] Calendar No\. (\d+)\.|Committee Agreed to Seek Consideration Under Suspension of the Rules|Ordered to be Reported", line, re.I)
if m != None:
# TODO: This makes no sense.
if prev_state in ("INTRODUCED", "REFERRED"):
attrs["state"] = "REPORTED"
attrs["nodename"] = "calendar"
# TODO: Useless.
attrs["calendar"] = m.group(2)
attrs["under"] = m.group(4)
attrs["number"] = m.group(5)
m = re.search(r"Committee on (.*)\. Reported by", line, re.I)
if m != None:
attrs["nodename"] = "reported"
attrs["committee"] = m.group(1)
if prev_state in ("INTRODUCED", "REFERRED"):
attrs["state"] = "REPORTED"
m = re.search(r"Committee on (.*)\. Discharged (by Unanimous Consent)?", line, re.I)
if m != None:
attrs["committee"] = m.group(1)
attrs["nodename"] = "discharged"
if prev_state in ("INTRODUCED", "REFERRED"):
attrs["state"] = "REPORTED"
m = re.search("Cleared for White House|Presented to President", line, re.I)
if m != None:
attrs["nodename"] = "topresident"
m = re.search("Signed by President", line, re.I)
if m != None:
attrs["nodename"] = "signed"
m = re.search("Pocket Vetoed by President", line, re.I)
if m != None:
attrs["nodename"] = "vetoed"
attrs["pocket"] = "1"
attrs["state"] = "VETOED:POCKET"
m = re.search("Vetoed by President", line, re.I)
if m != None:
attrs["nodename"] = "vetod"
attrs["state"] = "PROV_KILL:VETO'"
m = re.search("Became (Public|Private) Law No: ([\d\-]+)\.", line, re.I)
if m != None:
attrs["nodename"] = "enacted"
if prev_state != "PROV_KILL:VETO" and not prev_state.startswith("VETOED:"):
attrs["state"] = "ENACTED:SIGNED"
else:
attrs["state"] = "ENACTED:VETO_OVERRIDE"
m = re.search(r"Referred to (the )?((House|Senate|Committee) [^\.]+).?", line, re.I)
if m != None:
attrs["nodename"] = "referral"
attrs["committee"] = m.group(2)
if prev_state == "INTRODUCED":
attrs["state"] = "REFERRED"
m = re.search(r"Referred to the Subcommittee on (.*[^\.]).?", line, re.I)
if m != None:
attrs["nodename"] = "referral"
attrs["subcommittee"] = m.group(1)
if prev_state == "INTRODUCED":
attrs["state"] = "REFERRED"
m = re.search(r"Received in the Senate and referred to (the )?(.*[^\.]).?", line, re.I)
if m != None:
attrs["nodename"] = "referral"
attrs["committee"] = m.group(2)
return attrs
# # REFORMAT
#
# my @ti;
# my $ti2;
# foreach $c (@TITLES) {
# my @cc = @{ $c };
# push @ti, "\t\t<title type=\"$cc[0]\" as=\"$cc[1]\">$cc[2]</title>";
# }
# $ti2 = join("\n", @ti);
#
# my @cos;
# my $cos2;
# foreach $c (keys(%COSPONSORS)) {
# my $j = "joined=\"$COSPONSORS{$c}{added}\"";
# my $r = ($COSPONSORS{$c}{removed} ? " withdrawn=\"$COSPONSORS{$c}{removed}\"" : '');
# push @cos, "\t\t<cosponsor id=\"$c\" $j$r/>";
# }
# $cos2 = join("\n", @cos);
# if ($COSPONSORS_MISSING) { $COSPONSORS_MISSING = ' missing-unrecognized-person="1"'; } else { $COSPONSORS_MISSING = ''; }
#
# my @act;
# my $act2;
# my $laststate = '';
# foreach $c (sort( { CompareDates($$a[0][0], $$b[0][0]); } @ACTIONS)) {
# my @cc = @{ $c };
# my $ccstate = shift(@cc);
# my $ccc = shift(@cc);
# my ($ccdate, $cccommittee, $ccsubcommittee) = @{ $ccstate };
# my $axncom;
# if (defined($cccommittee)) {
# $axncom = "<committee name=\"" . htmlify($cccommittee) . "\"";
# if (defined($ccsubcommittee)) {
# $axncom .= " subcommittee=\"" . htmlify($ccsubcommittee) . "\"";
# }
# $axncom .= "/>";
# }
# if ($ccc == 1) {
# $cc[2] =~ s/<\/?[^>]+>//g;
# push @act, "\t\t<action $cc[0]>$axncom" . ParseActionText($cc[1]) . "</action>";
# } else {
# my $s = "<$cc[0] ";
# my %sk = %{ $cc[2] };
# foreach my $k (keys(%sk)) { if ($sk{$k} eq "") { next; } $s .= "$k=\"$sk{$k}\" "; }
# if ($cc[3] ne '' && $cc[3][0] ne $laststate) { $s .= " state=\"" . $cc[3][0] . "\""; $laststate = $cc[3][0]; }
# $s .= ">$axncom" . ParseActionText($cc[1]) . "</$cc[0]>";
# push @act, "\t\t$s";
# }
# }
# $act2 = join("\n", @act);
#
# # Load master committee XML file.
# if (!$committee_xml_master) { $committee_xml_master = $XMLPARSER->parse_file('../data/us/committees.xml'); }
# my @com;
# my $com2;
# foreach $c (@COMMITTEES) {
# my @cc = @{ $c };
# my $ccode;
# my ($cnode) = $committee_xml_master->findnodes("committees/committee[thomas-names/name[\@session=$SESSION] = \"$cc[0]\"]");
# if (!$cnode) {
# warn "Committee not found: $cc[0]";
# } else {
# if ($cc[1] eq '') {
# $ccode = $cnode->getAttribute('code');
# } else {
# my ($csnode) = $cnode->findnodes("subcommittee[thomas-names/name[\@session=$SESSION] = \"$cc[1]\"]");
# if (!$csnode) {
# #warn "Subcommittee not found: $cc[0] -- $cc[1]";
# } else {
# $ccode = $cnode->getAttribute('code') . '-' . $csnode->getAttribute('code');
# }
# }
# }
# $cc[0] = htmlify($cc[0]);
# $cc[1] = htmlify($cc[1]);
# my $s = "";
# if ($cc[1] ne "") {
# $s = " subcommittee=\"$cc[1]\"";
# }
# push @com, "\t\t<committee code=\"$ccode\" name=\"$cc[0]\"$s activity=\"$cc[2]\" />";
# }
# $com2 = join("\n", @com);
#
# my @rb;
# my $rb2;
# foreach $c (@RELATEDBILLS) {
# my @cc = @{ $c };
# push @rb, "\t\t<bill relation=\"$cc[0]\" session=\"$cc[1]\" type=\"$cc[2]\" number=\"$cc[3]\" />";
# }
# $rb2 = join("\n", @rb);
#
# my @crs;
# my $crs2;
# foreach $c (@CRS) {
# push @crs, "\t\t<term name=\"$c\"/>";
# }
# $crs2 = join("\n", @crs);
#
# my @amdts;
# my $amdts;
# foreach my $a (@AMENDMENTS) {
# push @amdts, "\t\t<amendment number=\"$a\"/>";
# }
# $amdts = join("\n", @amdts);
#
# # reformat summary
# $SUMMARY =~ s/\(There (is|are) \d+ other summar(y|ies)\)//;
# $SUMMARY =~ s/<p>/\n/ig;
# $SUMMARY =~ s/<br\/?>/\n/ig;
# $SUMMARY =~ s/<\/ul>/\n/ig;
# $SUMMARY =~ s/<li>/\n-/ig;
# $SUMMARY =~ s/<[^>]+?>//g;
# $SUMMARY =~ s/\ / /g;
# my $SUMMARY2 = HTMLify($SUMMARY);
#
# mkdir "../data/us/$SESSION/bills";
# mkdir "../data/us/$SESSION/bills.summary";
#
# open XML, ">$xfn";
# binmode(XML, ":utf8");
# print XML <<EOF;
#
# EOF
# close XML;
#
# open SUMMARY, ">", "../data/us/$SESSION/bills.summary/$BILLTYPE$BILLNUMBER.summary.xml";
# binmode(SUMMARY, ":utf8");
# print SUMMARY FormatBillSummary($SUMMARY2);
# close SUMMARY;
#
# IndexBill($SESSION, $BILLTYPE, $BILLNUMBER);
#
# return 1;
# }
#
# sub ParseAmendment {
# my $session = shift;
# my $chamber = shift;
# my $char = shift;
# my $number = shift;
#
# if ($ENV{SKIP_AMENDMENTS}) { return; }
#
# `mkdir -p ../data/us/$session/bills.amdt`;
# my $fn = "../data/us/$session/bills.amdt/$chamber$number.xml";
#
# print "Fetching amendment $session:$chamber$number\n" if (!$OUTPUT_ERRORS_ONLY);
#
# my $session2 = sprintf("%03d", $session);
#
# my $URL = "http://thomas.loc.gov/cgi-bin/bdquery/z?d$session2:$chamber$char$number:";
#
# my ($content, $mtime) = Download($URL);
# if (!$content) { return; }
# my $updated = DateToISOString($mtime);
#
# $content =~ s/\r//g;
#
# my $billtype;
# my $billnumber;
# my $sequence = '';
# my $sponsor;
# my $offered;
# my $description;
# my $purpose;
# my $status = 'offered';
# my $statusdate;
# my $actions = '';
#
# my ($sptitle, $spname, $spstate, $spcommittee);
#
# foreach my $line (split(/\n/, $content)) {
# $line =~ s/<\/?font[^>]*>//g;
#
# if ($line =~ /(<br \/>)?Amends: [^>]*>\s*$BillPattern/i) {
# $billtype = $BillTypeMap{lc($2)};
# $billnumber = $3;
# } elsif ($line =~ /^ \(A(\d\d\d)\)/) {
# $sequence = int($1);
# } elsif ($line =~ /(<br \/>)?Sponsor: <a [^>]*>(Rep|Sen) ([^<]*)<\/a> \[(\w\w(-\d+)?)\]/) {
# ($sptitle, $spname, $spstate) = ($2, $3, $4);
# } elsif ($line =~ /(<br \/>)?Sponsor: <a [^>]*>((House|Senate) [^<]*)<\/a>/) {
# ($spcommittee) = ($2);
# } elsif ($line =~ /\((submitted|offered) (\d+\/\d+\/\d\d\d\d)\)/) {
# $offered = $2;
# if ($sptitle eq "") { next; }
# $sponsor = PersonDBGetID(
# title => $sptitle,
# name => $spname,
# state => $spstate,
# when => ParseTime($offered));
# if (!defined($sponsor)) { warn "parsing amendment $session:$chamber$number: Unknown sponsor: $sptitle, $spname, $spstate (bill not fetched)"; return; }
# } elsif ($line =~ s/^<p>AMENDMENT DESCRIPTION:(<br \/>)?//) {
# $description = $line;
# } elsif ($line =~ s/^<p>AMENDMENT PURPOSE:(<br \/>)?//) {
# $purpose = $line;
# if ($description eq "") { $description = $purpose; }
# } elsif ($line =~ /<dt><strong>(\d+\/\d+\/\d\d\d\d( \d+:\d\d(am|pm))?):<\/strong><dd>([\w\W]*)/) {
# my ($when, $axn) = ($1, $4);
# $axn = HTMLify($axn);
# my $axnxml = ParseActionText($axn);
#
# my $statusdateattrs = "datetime=\"" . ParseDateTime($when) . "\"";
#
# if ($axn =~ /On agreeing to the .* amendment (\(.*\) )?(Agreed to|Failed) (without objection|by [^\.:]+|by recorded vote: (\d+) - (\d+)(, \d+ Present)? \(Roll no. (\d+)\))\./) {
# my ($passfail, $method) = ($2, $3);
# if ($passfail =~ /Agree/) { $passfail = "pass"; } else { $passfail = "fail"; }
# my $rollattr = "";
# if ($method =~ /recorded vote/) {
# $method =~ /\(Roll no. (\d+)\)/;
# my $roll = $1;
# $method = "roll";
# $rollattr = " roll=\"$roll\"";
#
# if (lc($chamber) eq "h") { GetHouseVote(YearFromDate(ParseTime($when)), $roll, 1); }
# else { warn "parsing amendment $session:$chamber$number: House-style vote on Senate amendment?"; }
# }
# $actions .= "\t\t<vote $statusdateattrs result=\"$passfail\" how=\"$method\"$rollattr>$axnxml</vote>\n";
# $status = $passfail;
# $statusdate = $statusdateattrs;
# } elsif ($axn =~ /(Motion to table )?Amendment SA \d+ (as modified )?(agreed to|not agreed to) in Senate by ([^\.:\-]+|Yea-Nay( Vote)?. (\d+) - (\d+)(, \d+ Present)?. Record Vote Number: (\d+))\./i) {
# my ($totable, $passfail, $method) = ($1, $3, $4);
# if ($passfail !~ /not/) { $passfail = "pass"; } else { $passfail = "fail"; }
#
# if ($totable) {
# if ($passfail eq 'fail') { next; }
# $passfail = 'fail'; # i.e. treat a passed motion to table as a failed vote on accepting the amendment
# }
#
# my $rollattr = "";
# if ($method =~ /Yea-Nay/) {
# $method =~ /Record Vote Number: (\d+)/;
# my $roll = $1;
# $method = "roll";
# $rollattr = " roll=\"$roll\"";
#
# if (lc($chamber) eq "s") { GetSenateVote($session, SubSessionFromDateTime(ParseDateTime($when)), YearFromDate(ParseTime($when)), $roll, 1); }
# else { warn "parsing amendment $session:$chamber$number: Senate-style vote on House amendment?"; }
# }
# $actions .= "\t\t<vote $statusdateattrs result=\"$passfail\" how=\"$method\"$rollattr>$axnxml</vote>\n";
# $status = $passfail;
# $statusdate = $statusdateattrs;
# } elsif ($axn =~ /Proposed amendment SA \d+ withdrawn in Senate./
# || $axn =~ /the [\w\W]+ amendment was withdrawn./) {
# $actions .= "\t\t<withdrawn $statusdateattrs>$axnxml</withdrawn>\n";
# $status = "withdrawn";
# $statusdate = $statusdateattrs;
# } else {
# $actions .= "\t\t<action $statusdateattrs>$axnxml</action>\n";
# }
# }
# }
#
# if (!defined($purpose)) { $purpose = "Amendment information not available."; $description = $purpose; }
#
# if (!defined($billtype) || (!defined($sponsor) && !defined($spcommittee)) || !defined($offered)) {
# print "Parse failed on amendment: $URL\n";
# return;
# }
#
# $description = HTMLify(ToUTF8($description));
# $purpose = HTMLify(ToUTF8($purpose));
#
# $offered = "datetime=\"" . ParseDateTime($offered) . "\"";
# if ($status eq "offered") { $statusdate = $offered; }
#
# my $sponsorxml;
# if (defined($sponsor)) { $sponsorxml = "id=\"$sponsor\""; }
# else { $sponsorxml = "committee=\"" . htmlify($spcommittee) . "\""; }
#
# open XML, ">", "$fn";
# print XML <<EOF;
# <amendment session="$session" chamber="$chamber" number="$number" updated="$updated">
# <amends type="$billtype" number="$billnumber" sequence="$sequence"/>
# <status $statusdate>$status</status>
# <sponsor $sponsorxml/>
# <offered $offered/>
# <description>$description</description>
# <purpose>$purpose</purpose>
# <actions>
# $actions
# </actions>