This repository has been archived by the owner on May 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_status.pl
1542 lines (1309 loc) · 50.2 KB
/
parse_status.pl
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
# OUTPUT_ERRORS_ONLY=1 perl parse_status.pl ALL 112 2>&1 | tee -a log.txt
# for x in {111..93}; do echo $x; CACHED=1 SKIP_AMENDMENTS=1 OUTPUT_ERRORS_ONLY=1 perl parse_status.pl ALL $x 2>&1 | tee -a log.txt; done;
# SKIP_INDEX=1
use Time::Local;
use LWP::UserAgent;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use HTML::Entities;
require "general.pl";
require "persondb.pl";
#require "parse_rollcall.pl";
require "indexing.pl";
if ($ENV{OUTPUT_ERRORS_ONLY}) { $OUTPUT_ERRORS_ONLY = 1; }
if ($ARGV[0] eq "PARSE_STATUS") { &Main; }
if ($ARGV[0] eq "PARSE_STATUS_STDIN") { &Main2; }
if ($ARGV[0] eq "REFRESH") { GovDBOpen(); RefreshBills($ARGV[1], $ARGV[2], $ARGV[3]); DBClose(); }
if ($ARGV[0] eq "UPDATE" || $ARGV[0] eq "ALL" || $ARGV[0] eq "MISSING") { GovDBOpen(); UpdateBills($ARGV[1], $ARGV[0] eq "UPDATE" ? 0 : $ARGV[0]); DBClose(); }
if ($ARGV[0] eq "ALLAMENDMENTS") { &AllAmendments; }
if ($ARGV[0] eq "SUMMARIES") { &DoSummaries; }
1;
sub Main {
&GovDBOpen;
GovGetBill($ARGV[1], $ARGV[2], $ARGV[3], 0, []);
&DBClose;
}
sub Main2 {
&GovDBOpen;
while (!eof(STDIN)) {
my $l = <STDIN>; chop $l;
GovGetBill(split(/\s/, $l));
}
&DBClose;
}
sub UpdateBills {
my $SESSION = shift;
my $ALL = shift;
my $changefile = "../data/us/$SESSION/bills.bsshash";
my %changehash;
open CHANGES, "<$changefile";
while (!eof(CHANGES)) {
my $line = <CHANGES>; chop $line;
my @fields = split(/ /, $line);
$changehash{$fields[0]} = $fields[1];
}
close CHANGES;
my $SESSION2 = sprintf("%03d", $SESSION);
for my $tbt ('HC', 'HE', 'HJ', 'HR', 'HZ', 'SC', 'SE', 'SJ', 'SN', 'SP') {
my $lastseq;
my $offset = 0;
my ($seq, $bt, $bn, $rec);
while (defined($offset)) {
my $url = "http://thomas.loc.gov/cgi-bin/bdquery/d?d$SESSION2:$offset:./list/bss/d$SESSION2$tbt.lst:\[\[o\]\]";
print "$url\n";
undef $offset;
my ($content, $mtime) = Download($url);
if (!$content) { warn; return; }
my @lines = split(/[\n\r]/, $content);
for my $line (@lines) {
if ($line =~ /(.*)<hr>/) {
if (defined($rec)) {
$rec .= $1;
UpdateBills2($SESSION, $bt, $bn, $rec, \%changehash, $ALL);
}
undef $bt;
undef $bn;
undef $rec;
}
if ($line =~ m|<B>\s*(\d+)\.</B> <a href="/cgi-bin/bdquery/D\?d$SESSION2:\d+:./list/bss/d$SESSION2$tbt.lst::">\s*$BillAmendmentPattern\s*</A>|i) {
if (defined($rec)) {
UpdateBills2($SESSION, $bt, $bn, $rec, \%changehash, $ALL);
}
($seq, $bt, $bn) = ($1, $2, $3);
undef $rec;
if (defined($lastseq) && $lastseq != $seq-1) { warn "Skipped a sequence number $lastseq to $seq."; }
$lastseq = $seq;
if ($tbt eq 'HZ' || $tbt eq 'SP') {
$bt = $tbt;
} else {
$bt = $BillTypeMap{lc($bt)};
}
} elsif (defined($bt)) {
$rec .= $line;
}
if ($line =~ m|<a href="/cgi-bin/bdquery/d\?d$SESSION2:(\d+)[^"]*">NEXT PAGE</a>|i) {
$offset = $1;
}
}
}
if (!defined($lastseq)) {
warn "No $tbt bills."
}
if (defined($rec)) {
UpdateBills2($SESSION, $bt, $bn, $rec, \%changehash, $ALL);
}
}
open CHANGES, ">$changefile";
for my $key (sort(keys(%changehash))) {
print CHANGES "$key $changehash{$key}\n";
}
close CHANGES;
}
sub UpdateBills2 {
my ($bs, $bt, $bn, $rec, $changehash, $ignorehash) = @_;
#print "<<$rec>>\n";
$rec = md5_base64($rec);
if ($$changehash{"$bt$bn"} eq $rec && !$ignorehash) { return; }
print "Detected Update to $bt$bs-$bn.\n" if (!$OUTPUT_ERRORS_ONLY && !$ignorehash);
if ($bt eq 'HZ') {
if (!ParseAmendment($bs, 'h', 'Z', $bn)) { return; }
} elsif ($bt eq 'SP') {
if (!ParseAmendment($bs, 's', 'P', $bn)) { return; }
} else {
if (!GovGetBill($bs, $bt, $bn, $ignorehash eq "MISSING")) { return; }
}
$$changehash{"$bt$bn"} = $rec;
}
sub RefreshBills {
my ($session, $xpath, $pattern, $dontwarnifunchanged) = @_;
my @bills = GetBillList($session);
my @rlist;
foreach $bill_ (@bills) {
my $bill;
eval { $bill = GetBill(@{ $bill_ }); };
# Failed to parse?
if ($@) {
print "$$bill_[0] $$bill_[1] $$bill_[2]:$@\n";
GovGetBill( $$bill_[0], $$bill_[1], $$bill_[2] );
next;
}
# The wrong bill is inside the file!
if ("$$bill_[1]$$bill_[0]-$$bill_[2]" ne $bill->findvalue('concat(@type,@session,"-",@number)')) {
print "Deleting $$bill_[1]$$bill_[0]-$$bill_[2] because the wrong bill is inside!\n";
unlink "../data/us/$session/bills/$$bill_[1]$$bill_[2].xml";
next;
}
if ($xpath ne '' && RefreshTest($bill, $xpath, $pattern)) {
push @rlist, $bill_;
}
}
print "Found " . scalar(@rlist ) . " bills to refresh.\n";
for my $bill_ (@rlist) {
GovGetBill( $$bill_[0], $$bill_[1], $$bill_[2] );
if (!$dontwarnifunchanged) {
$bill = GetBill(@{ $bill_ });
if (RefreshTest($bill, $xpath, $pattern)) {
print "$$bill_[0]$$bill_[1]$$bill_[2]: XPath expression still matches.\n";
}
}
}
}
sub AllAmendments {
my $session = $ARGV[1];
my $xpath = $ARGV[2];
my $pattern = $ARGV[3];
&GovDBOpen;
my @bills = GetBillList($session);
foreach $bill_ (@bills) {
my $bill = GetBill(@{ $bill_ });
my $billtype = $bill->getAttribute('type');
my $billnumber = $bill->getAttribute('number');
foreach my $a ($bill->findnodes("amendments/amendment")) {
if ($xpath ne "") {
my $af = "../data/us/$session/bills.amdt/" . $a->getAttribute('number') . ".xml";
if (-e $af) {
my $ax = $XMLPARSER->parse_file($af);
if (!RefreshTest($ax, $xpath, $pattern)) { next; }
}
}
$a->getAttribute('number') =~ /(h|s)(\d+)/;
my ($ch, $num) = ($1, $2);
my $char;
if ($ch eq "h") { $char = 'Z'; } else { $char = 'P'; }
ParseAmendment($session, $ch, $char, $num, $billtype, $billnumber);
}
}
&DBClose;
}
sub RefreshTest {
my $bill = shift;
my $xpath = shift;
my $pattern = shift;
if ($pattern eq "") {
my $value = $bill->findvalue($xpath);
return $value eq "true";
} elsif ($pattern eq "EXISTS") {
my @value = $bill->findnodes($xpath);
return scalar(@value) > 0;
} elsif ($pattern eq "CHECKPERSONID") {
foreach my $node ($bill->findnodes($xpath)) {
my $id = $node->textContent;
if ($id eq "") { next; }
if (defined($CHECKPERSONID{$id})) {
if ($CHECKPERSONID{$id}) { return 1; }
next;
}
print "$id\n";
my ($ex) = DBSelectFirst(people, [id], ["id=$id"]);
$CHECKPERSONID{$id} = !defined($ex);
if (!defined($ex)) {
print "$id\n";
return 1;
}
}
return 0;
} else {
foreach my $node ($bill->findnodes($xpath)) {
if ($node->textContent =~ /$pattern/) { return 1; }
}
return 0;
}
}
sub AllSession {
&GovDBOpen;
GovGetAllBills($ARGV[1], $ARGV[2]);
&DBClose;
}
sub GovGetAllBills {
my $SESSION = shift; # Session number
my $SKIPIFEXISTS = shift;
my $URL = "http://frwebgate.access.gpo.gov/cgi-bin/BillBrowse.cgi?dbname=" . $SESSION . "_cong_bills&wrapperTemplate=all" . $SESSION . "bills_wrapper.html&billtype=all";
print $URL . "\n";
my ($content, $mtime) = Download($URL);
if (!$content) { return; }
my %billstatuses = ();
my @bills = ();
while ($content =~ m/cong_bills\&docid=f\:([a-z]+)(\d+)(\w+)\.txt[\n\r]"/g) {
my $billtype = $1;
my $billnumber = $2;
my $billstatus = $3;
push @bills, [$billtype, $billnumber];
push @{ $billstatuses{$billtype . $billnumber} }, $billstatus;
}
my $lastb;
foreach my $b (@bills) {
my @bb = @{ $b };
if ($lastb eq $bb[0] . $bb[1]) { next; }
$lastb = $bb[0] . $bb[1];
#if (!($bb[0] eq "sj" || $bb[0] eq "sc" || $bb[0] eq "hj" || $bb[0] eq "hc")) { next; }
#if ($bb[0] =~ "^h") { next; }
GovGetBill($SESSION, $bb[0], $bb[1], $SKIPIFEXISTS, $billstatuses{$bb[0] . $bb[1]});
}
}
sub GovGetBill {
my $SESSION = shift; # Session number
my $BILLTYPE = shift; # h, hc, hj, hr, s, sc, sj, sr (case insens.)
my $BILLNUMBER = shift;
my $SKIPIFEXISTS = shift;
my @BILLSTATUSES = @{ $_[0]; }; shift;
if ($BILLNUMBER eq "") { die "No bill number given."; }
my $SESSION2 = sprintf("%03d", $SESSION);
my $xfn = "../data/us/$SESSION/bills/$BILLTYPE$BILLNUMBER.xml";
if ($SKIPIFEXISTS && -e $xfn) { return; }
if ($ENV{SKIP_RECENT} && -M $xfn < 4) { return; }
if ($ENV{SKIP_RECENT}) {
open F, $xfn;
my $line = <F>;
close F;
if ($line =~ /updated="2009-11-13T/) {
return;
}
}
print "Fetching $SESSION:$BILLTYPE$BILLNUMBER\n" if (!$OUTPUT_ERRORS_ONLY);
my $BILLTYPE2 = $BILLTYPE;
if ($BILLTYPE2 eq "hr") { $BILLTYPE2 = "hres"; }
my $URL = "http://thomas.loc.gov/cgi-bin/bdquery/z?d$SESSION2:$BILLTYPE2$BILLNUMBER:\@\@\@X";
my ($content, $mtime) = Download($URL);
if (!$content) { return; }
my $updated = DateToISOString($mtime);
$content =~ s/\n\r/\n/g;
$content =~ s/\r/ /g; # amazing, stray carriage returns
my @content = split(/\n+/, $content);
my $SPONSOR_TITLE = undef;
my $SPONSOR_NAME = undef;
my $SPONSOR_STATE = undef;
my $SPONSOR_ID = undef;
my $INTRODUCED = undef;
my $INTRODUCED2 = undef;
my @ACTIONS = ();
my @COMMITTEES = ();
my @COSPONSORS = ();
my $COSPONSORS_MISSING = 0;
my @RELATEDBILLS = ();
my @TITLES = ();
my $STATUSNOW;
my $STATUS_ON_TABLE_MOTION;
my @CRS = ();
my @AMENDMENTS = ();
my $STATE = '';
my $lastcommittee = undef;
my $titles = undef;
my $backup_title;
my $wasvetoed = 0;
my $conferenceagreed = 0;
my $action_substate = -1; # there is an initial DL to start off the main list
my $action_committee = undef;
my $action_subcommittee = undef;
while (scalar(@content) > 0) {
my $cline = shift(@content);
# SPONSOR
if ($cline =~ /(<br \/>)?<b>Sponsor: <\/b>(No Sponsor|<a ([^>]+)>([\w\W]*)<\/a>\s+\[(\w\w(-\d+)?)\])/i) {
my $SPONSOR_TEXT = $2;
$SPONSOR_NAME = $4;
$SPONSOR_STATE = $5;
$SPONSOR_A_ATTRS = $3;
while (scalar(@content) > 0) {
my $cline = shift(@content);
if ($cline =~ /(\(by request\) )?\(introduced ([\d\/]+)\)/i) {
$INTRODUCED = $2;
last;
}
}
$INTRODUCED2 = ParseDateTime($INTRODUCED);
$INTRODUCED = ParseTime($INTRODUCED);
# Some bills (109th's debt ceiling limit) have No Sponsor.
if ($SPONSOR_TEXT ne "No Sponsor") {
if ($SPONSOR_NAME =~ s/^(Sen|Rep)\.?\s+//i) { $SPONSOR_TITLE = $1; }
$SPONSOR_NAME =~ s/Colordao/Colorado/; # typo
if ($SPONSOR_A_ATTRS =~ /FLD003\+\@4\(\(\@1\([^"]+\)\)\+(\d{5})\)/) {
# Starting in 2013, try THOMAS IDs first. More reliable? We're
# only doing historical data now anyway.
my $thomasid = $1;
my @ret = DBSelectFirst(people, [id], ["thomasid='$thomasid'"]);
$SPONSOR_ID = $ret[0];
}
if (!$SPONSOR_ID) {
$SPONSOR_ID = PersonDBGetID(
title => $SPONSOR_TITLE,
name => $SPONSOR_NAME,
state => $SPONSOR_STATE,
when => $INTRODUCED);
}
if (!defined($SPONSOR_ID)) { warn "parsing bill $BILLTYPE$SESSION-$BILLNUMBER: Unknown sponsor: $SPONSOR_TITLE, $SPONSOR_NAME, $SPONSOR_STATE"; return; }
else { $SPONSOR_ID = "id=\"$SPONSOR_ID\""; }
#if ($pid) {
# if ($ENV{CACHED} && $did_a_a{$pid}) { return; }
# if ($SPONSOR_A_ATTRS !~ /FLD003\+\@4\(\(\@1\([^"]+\)\)\+(\d{5})\)/) { warn "Sponsor <a> element not understood: $SPONSOR_A_ATTRS."; }
# DBUpdate(LOW_PRIORITY, 'people', ["id=$pid"], thomasid=>$1);
# $did_a_a{$pid} = 1;
# if ($ENV{CACHED}) { return; }
#}
} else {
$SPONSOR_ID = "none=\"true\"";
}
$STATUSNOW = "<introduced datetime=\"$INTRODUCED2\"/>";
$STATE = ['INTRODUCED', $INTRODUCED2, { sponsor => $SPONSOR_ID }];
# BACKUP TITLE
} elsif ($cline =~ /<B>(Latest )?Title:<\/B> ([\w\W]+)/i) {
if ($2 =~ /Reserved for the /) {
print "parsing bill $BILLTYPE$SESSION-$BILLNUMBER: Skipping bill 'Reserved for ...'";
return;
}
$backup_title = ['official', 'introduced', HTMLify($2)];
# ACTIONS
} elsif ($cline =~ /<dt><strong>([\d\/ :apm]+):<\/strong><dd>([\w\W]+)/i) {
my $when_old = $1;
my $when = $1;
my $what = $2;
$what = HTMLify($what);
$when_old = ParseTime($when_old);
$when = ParseDateTime($when);
my $statusdateattrs = "datetime=\"$when\"";
my @axndateattrs = (datetime => $when); # date => $when_old
# skip actions about amendments
if ($what =~ /^[SH].AMDT.\d+/) { next; }
if ($cline =~ /^<dl>/) { $action_substate++; }
if ($cline =~ /^<\/dl>/) { $action_substate--; }
my $action_state = [$when];
if ($action_substate == 1) { $action_state = [$when, $action_committee]; }
if ($action_substate == 2) { $action_state = [$when, $action_committee, $action_subcommittee]; }
# house vote
$what =~ s/, the Passed/, Passed/g; # 106 h4733 and others
if ($what =~ /(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|Measure 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+\)|roll call \#(\d+) \(\d+-\d+\))/i
|| $what =~ /^Measure passed House/) {
my $motion = $1;
my $isoverride = $2;
my $asamended = $3;
my $passfail = $4;
my $how = $5;
if ($what =~ /^Measure passed House/) {
$motion = "Passed House";
$isoverride = 0;
$asamended = ($what =~ /, amended/);
$passfail = "Pass";
$how = "(method not recorded)";
}
if ($motion =~ /Passed House|House Agreed to|Measure passed House/) { $passfail = 'Pass'; }
my $votetype;
my $roll = "";
if ($passfail =~ /Pass|Agreed/) { $passfail = "pass"; }
else { $passfail = "fail"; }
if ($wasvetoed && $motion =~ /Two-thirds of the Members present/) {
$isoverride = 1;
}
if ($wasvetoed && !$isoverride) {
warn "A vote after a veto?? Maybe we need to parse this as an override.";
}
if ($isoverride) {
$votetype = "override";
} elsif ($motion =~ /(agree (with an amendment )?to|concur in) the Senate amendment/i) {
$votetype = "pingpong";
} elsif ($motion =~ /conference report/) {
$votetype = "conference";
} elsif ($BILLTYPE =~ /^h/) {
$votetype = "vote";
} else {
$votetype = "vote2";
}
if ($what =~ /\((Roll no\.|Record Vote No:) (\d+)\)/i) {
$roll = $2;
$how = "roll";
} elsif ($what =~ /roll call \#(\d+) \(\d+-\d+\)/i) {
$roll = $1;
$how = "roll";
}
my $suspension;
if ($motion =~ /On motion to suspend the rules/ && $how eq 'roll') {
$suspension = 1;
}
my $prevstatus = $STATUSNOW;
if ($votetype eq 'vote' || $votetype eq "vote2") {
$STATUSNOW = "<$votetype $statusdateattrs where=\"h\" result=\"$passfail\" how=\"$how\" roll=\"$roll\"/>";
}
#if ($roll != 0 && YearFromDateTime($when) >= 1990) { GetHouseVote(YearFromDateTime($when), $roll, 1); }
# Funny thing: on a motion to suspend the rules and
# pass, if the motion fails, the bill may still yet
# continue to be debated, or debate may end, probably
# with a "Motion to reconsider laid on the table Agreed
# to without objection."
undef $STATUS_ON_TABLE_MOTION; # another vote resets this
if ($motion =~ /On motion to suspend the rules/ && $passfail eq "fail") {
$STATUS_ON_TABLE_MOTION = $STATUSNOW;
$STATUSNOW = $prevstatus;
}
if ($votetype eq 'vote' || $votetype eq 'vote2') {
# House vote on a House bill.
if ($BILLTYPE =~ /^h/) {
if ($passfail eq 'pass') {
if ($BILLTYPE eq 'hr') {
$STATE = ['PASSED:SIMPLERES', $when];
} else {
$STATE = ['PASS_OVER:HOUSE', $when]; # passed by originating chamber, now in second chamber
}
} elsif ($motion =~ /On motion to suspend the rules/) {
# Funny thing: on a motion to suspend the rules and
# pass, if the motion fails, the bill may still yet
# continue to be debated, or debate may end, probably
# with a "Motion to reconsider laid on the table Agreed
# to without objection."
$STATE = ['PROV_KILL:SUSPENSIONFAILED', $when]; # provisionally killed by failure to pass under suspension of the rules
} else {
# outright failure
$STATE = ['FAIL:ORIGINATING:HOUSE', $when];
}
# House vote on a Senate bill
} else {
if ($passfail eq 'pass') {
# This ignores the need to go to conference!
if (($BILLTYPE eq 'hj' || $BILLTYPE eq 'sj') && $backup_title =~ /Proposing an amendment to the Constitution of the United States/) {
# joint resolution that looks like an amendment to the constitution
$STATE = ['PASSED:CONSTAMEND', $when];
} elsif ($BILLTYPE eq 'hc' || $BILLTYPE eq 'sc') {
# concurrent resolutions
$STATE = ['PASSED:CONCURRENTRES', $when];
} elsif (!$asamended) {
# bills and joint resolutions not constitutional amendments, not amended from Senate version
$STATE = ['PASSED:BILL', $when]; # passed by second chamber, now on to president
} elsif ($asamended) {
# bills and joint resolutions not constitutional amendments, amended from Senate version.
# can go back to Senate, or conference committee
$STATE = ['PASS_BACK:HOUSE', $when];
}
} elsif ($motion =~ /On motion to suspend the rules/) {
# See note above.
$STATE = ['PROV_KILL:SUSPENSIONFAILED', $when]; # provisionally killed by failure to pass under suspension of the rules
} else {
# outright failure
$STATE = ['FAIL:SECOND:HOUSE', $when];
}
}
} elsif ($votetype eq 'override') {
# House override on a House bill.
if ($BILLTYPE =~ /^h/) {
if ($passfail eq 'pass') {
$STATE = ['OVERRIDE_PASS_OVER:HOUSE', $when]; # override ok in originating chamber, now in second chamber
} else {
# override failure
$STATE = ['VETOED:OVERRIDE_FAIL_ORIGINATING:HOUSE', $when];
}
# House override on a Senate bill
} else {
if ($passfail eq 'pass') {
# Wait till the enacted line appears.
} else {
# override failure
$STATE = ['VETOED:OVERRIDE_FAIL_SECOND:HOUSE', $when];
}
}
} elsif ($votetype eq "pingpong") {
# This is a motion to accept Senate amendments to the House's original bill.
# If the motion fails, I suppose it is a provisional kill. If it passes,
# then pingpong is over and the bill has passed both chambers.
if ($passfail eq 'pass') {
$STATE = ['PASSED:BILL', $when];
} else {
$STATE = ['PROV_KILL:PINGPONGFAIL', $when];
}
} elsif ($votetype eq "conference") {
# This is tricky to integrate into state because we have to wait for both
# chambers to pass the conference report.
if ($passfail eq 'pass') { $conferenceagreed++; }
if ($conferenceagreed == 2) {
$STATE = ['PASSED:BILL', $when];
}
}
push @ACTIONS, [$action_state, 2, "vote", $what, { @axndateattrs, where => 'h', type => $votetype, result => $passfail, how => $how, roll => $roll, suspension => $suspension }, $STATE ];
# senate vote
} elsif ($what =~ /(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|Senate agreed to House amendment|Senate concurred in the House amendment)(,?[\w\W]*,?) (without objection|by Unanimous Consent|by Voice Vote|by Yea-Nay( Vote)?\. \d+\s*-\s*\d+\. Record Vote (No|Number): \d+)/
|| $what eq "Measure passed Senate."
|| $what eq "Senate agreed to House amendments.") {
my $motion = $1;
my $passfail = $1;
my $junk = $2;
my $how = $3;
if ($what eq "Measure passed Senate." || $what eq "Senate agreed to House amendments.") {
if ($what eq "Measure passed Senate.") {
$motion = "Passed Senate";
} else {
$motion = $what;
}
$passfail = "Passed";
$junk = '';
$how = "(method not recorded)";
}
my $roll = "";
if ($passfail =~ /Passed|agreed|concurred/i) { $passfail = "pass"; }
else { $passfail = "fail"; }
my $votenode = 'vote';
if ($junk =~ /over veto/) {
$votetype = "override";
} elsif ($motion =~ /conference report/) {
$votetype = 'conference';
} elsif ($motion =~ /Cloture/) {
$votenode = "vote-aux";
$votetype = "cloture";
} elsif ($motion =~ /Senate agreed to House amendment|Senate concurred in the House amendment/) {
$votetype = "pingpong";
} elsif ($BILLTYPE =~ /^s/) {
$votetype = "vote";
} else {
$votetype = "vote2";
}
if ($what =~ /Record Vote (No|Number): (\d+)\./) {
$roll = $2;
$how = "roll";
}
if ($votenode eq 'vote') {
$STATUSNOW = "<$votetype $statusdateattrs where=\"s\" result=\"$passfail\" how=\"$how\" roll=\"$roll\"/>";
}
#if ($roll != 0 && $SESSION >= 101) { GetSenateVote($SESSION, SubSessionFromDateTime($when), YearFromDateTime($when), $roll, 1); }
if ($votetype eq "vote" || $votetype eq "vote2") {
# Senate vote on a Senate bill.
if ($BILLTYPE =~ /^s/) {
if ($passfail eq 'pass') {
if ($BILLTYPE eq 'sr') {
$STATE = ['PASSED:SIMPLERES', $when];
} else {
$STATE = ['PASS_OVER:SENATE', $when]; # passed by originating chamber, now in second chamber
}
} else {
# outright failure
$STATE = ['FAIL:ORIGINATING:SENATE', $when];
}
# Senate vote on a House bill
} else {
if ($passfail eq 'pass') {
# This ignores the need to go to conference!
if (($BILLTYPE eq 'hj' || $BILLTYPE eq 'sj') && $backup_title =~ /Proposing an amendment to the Constitution of the United States/) {
# joint resolution that looks like an amendment to the constitution
$STATE = ['PASSED:CONSTAMEND', $when];
} elsif ($BILLTYPE eq 'hc' || $BILLTYPE eq 'sc') {
# concurrent resolutions
$STATE = ['PASSED:CONCURRENTRES', $when];
} elsif ($junk !~ /with amendments|with an amendment/i) {
# bills and joint resolutions not constitutional amendments, no amendment
$STATE = ['PASSED:BILL', $when]; # passed by second chamber, now on to president
} else {
# bills and joint resolutions not constitutional amendments, amendment sends back to House
$STATE = ['PASS_BACK:SENATE', $when];
}
} elsif ($votetype eq 'cloture') {
# See note above.
$STATE = ['PROV_KILL:CLOTUREFAILED', $when];
} else {
# outright failure
$STATE = ['FAIL:SECOND:SENATE', $when];
}
}
} elsif ($votetype eq "override") {
# Senate override on a Senate bill.
if ($BILLTYPE =~ /^s/) {
if ($passfail eq 'pass') {
$STATE = ['OVERRIDE_PASS_OVER:SENATE', $when]; # override ok in originating chamber, now in second chamber
} else {
# override failure
$STATE = ['VETOED:OVERRIDE_FAIL_ORIGINATING:SENATE', $when];
}
# Senate override on a House bill
} else {
if ($passfail eq 'pass') {
# Wait till the enacted line appears.
} else {
# override failure
$STATE = ['VETOED:OVERRIDE_FAIL_SECOND:SENATE', $when];
}
}
} elsif ($votetype eq 'cloture' && $passfail eq 'fail') {
# A failed cloture vote is a provisional kill.
$STATE = ['PROV_KILL:CLOTUREFAILED', $when];
} elsif ($votetype eq "pingpong") {
# This is a motion to accept House amendments to the Senate's original bill.
# If the motion fails, I suppose it is a provisional kill. If it passes,
# then pingpong is over and the bill has passed both chambers.
if ($passfail ne 'pass') {
$STATE = ['PROV_KILL:PINGPONGFAIL', $when];
} elsif (($BILLTYPE eq 'hj' || $BILLTYPE eq 'sj') && $backup_title =~ /Proposing an amendment to the Constitution of the United States/) {
# joint resolution that looks like an amendment to the constitution
$STATE = ['PASSED:CONSTAMEND', $when];
} elsif ($BILLTYPE eq 'hc' || $BILLTYPE eq 'sc') {
# concurrent resolutions
$STATE = ['PASSED:CONCURRENTRES', $when];
} elsif ($what !~ /with an amendment/) {
$STATE = ['PASSED:BILL', $when];
} else {
$STATE = ['PASS_BACK:SENATE', $when];
}
} elsif ($votetype eq "conference") {
# This is tricky to integrate into state because we have to wait for both
# chambers to pass the conference report.
if ($passfail eq 'pass') { $conferenceagreed++; }
if ($conferenceagreed == 2) {
if (($BILLTYPE eq 'hj' || $BILLTYPE eq 'sj') && $backup_title =~ /Proposing an amendment to the Constitution of the United States/) {
# joint resolution that looks like an amendment to the constitution
$STATE = ['PASSED:CONSTAMEND', $when];
} elsif ($BILLTYPE eq 'hc' || $BILLTYPE eq 'sc') {
# concurrent resolutions
$STATE = ['PASSED:CONCURRENTRES', $when];
} else {
$STATE = ['PASSED:BILL', $when];
}
}
}
push @ACTIONS, [$action_state, 2, $votenode, $what, { @axndateattrs, where => 's', type => $votetype, result => $passfail, how => $how, roll => $roll }, $STATE ];
} elsif ($what =~ /Placed on (the )?([\w ]+) Calendar( under ([\w ]+))?[,\.] Calendar No\. (\d+)\.|Committee Agreed to Seek Consideration Under Suspension of the Rules|Ordered to be Reported/i) {
if ($STATUSNOW =~ /^<introduced/) {
$STATUSNOW = "<calendar $statusdateattrs />";
}
if ($$STATE[0] eq 'INTRODUCED' || $$STATE[0] eq 'REFERRED') {
$STATE = ['REPORTED', $when];
}
push @ACTIONS, [$action_state, 2, "calendar", $what, { @axndateattrs, calendar => $2, under => $4, number => $5 }, $STATE];
} elsif ($what =~ /Cleared for White House|Presented to President/) {
$STATUSNOW = "<topresident $statusdateattrs />";
push @ACTIONS, [$action_state, 2, "topresident", $what, { @axndateattrs }, $STATE];
} elsif ($what =~ /Signed by President/) {
$STATUSNOW = "<signed $statusdateattrs />";
push @ACTIONS, [$action_state, 2, "signed", $what, { @axndateattrs }, $STATE];
} elsif ($what =~ /Pocket Vetoed by President/) {
$STATUSNOW = "<veto pocket=\"1\" $statusdateattrs />";
$wasvetoed = 1;
$STATE = ['VETOED:POCKET', $when];
push @ACTIONS, [$action_state, 2, "vetoed", $what, { @axndateattrs, pocket => 1 }, $STATE];
} elsif ($what =~ /Vetoed by President/) {
$STATUSNOW = "<veto $statusdateattrs />";
$wasvetoed = 1;
$STATE = ['PROV_KILL:VETO', $when]; # could be overridden
push @ACTIONS, [$action_state, 2, "vetoed", $what, { @axndateattrs }, $STATE];
} elsif ($what =~ /^(Became )?(Public|Private) Law( No:)? ([\d\-]+)\./i) {
$STATUSNOW = "<enacted $statusdateattrs />";
if (!$wasvetoed) {
$STATE = ['ENACTED:SIGNED', $when, {type => lc($2), number => $4}];
} else {
$STATE = ['ENACTED:VETO_OVERRIDE', $when, {type => lc($2), number => $4}];
}
push @ACTIONS, [$action_state, 2, "enacted", $what, { @axndateattrs, type => lc($2), number => $4 }, $STATE];
} elsif ($what =~ /Passed House pursuant to/) {
my $votetype;
my $how = "by special rule";
if ($BILLTYPE =~ /^h/) { $votetype = "vote"; } else { $votetype = "vote2"; }
$STATUSNOW = "<$votetype $statusdateattrs where=\"h\" result=\"pass\" how=\"$how\"/>";
if ($BILLTYPE eq 'hr') {
$STATE = ['PASSED:SIMPLERES', $when];
} elsif ($BILLTYPE =~ /^h/) {
$STATE = ['PASS_OVER:HOUSE', $when]; # passed by originating chamber, now in second chamber
} elsif ($BILLTYPE eq 'sj' && $backup_title =~ /Proposing an amendment to the Constitution of the United States/) {
# joint resolution that looks like an amendment to the constitution
$STATE = ['PASSED:CONSTAMEND', $when];
} elsif ($BILLTYPE eq 'sc') {
# concurrent resolutions
$STATE = ['PASSED:CONCURRENTRES', $when];
} else {
# bills and joint resolutions not constitutional amendments
$STATE = ['PASSED:BILL', $when]; # passed by second chamber, now on to president
}
push @ACTIONS, [$action_state, 2, "vote", $what, { @axndateattrs, where => 'h', type => $votetype, result => 'pass', how => $how }, $STATE ];
} elsif ($what =~ /Motion to reconsider laid on the table Agreed to without objection/) {
# that's the end of that bill
if (defined($STATUS_ON_TABLE_MOTION)) {
$STATUSNOW = $STATUS_ON_TABLE_MOTION;
undef $STATUS_ON_TABLE_MOTION;
}
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^(Read twice and )?[Rr]eferred to (the )?((House|Senate|Committee) .*[^\.]).?/) {
$action_committee = $3;
if ($$STATE[0] eq 'INTRODUCED') {
$STATE = ['REFERRED', $when];
}
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Received in the Senate and referred to (the )?(.*[^\.]).?/) {
$action_committee = $2;
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Received in the Senate/) {
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Message on Senate action sent to the House/) {
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Referred to the Subcommittee on (.*[^\.]).?/) {
$action_subcommittee = $1;
if ($$STATE[0] eq 'INTRODUCED') {
$STATE = ['REFERRED', $when];
}
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Reported by|discharged (by Unanimous Consent)?\./i) {
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} elsif ($what =~ /^Considered as privileged matter|^Considered under suspension of the rules|^Considered as unfinished business|moved to|DEBATE|^Considered by unanimous consent|Committee Consideration and Mark-up Session Held|Sponsor introductory remarks on measure/) {
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
} else {
#print "$BILLTYPE$SESSION-$BILLNUMBER: Unparsed action: $what\n";
push @ACTIONS, [$action_state, 1, $statusdateattrs, $what, undef, $STATE];
}
}
}
if (!defined($INTRODUCED)) {
warn "parsing bill $BILLTYPE$SESSION-$BILLNUMBER: Failed parse, no introduced date found: $URL (sponsor $SPONSOR_NAME)";
return;
}
my $mtime2;
# COSPONSORS
my %cosponsors_seen = ();
$URL =~ s/\@[\w\W]*$/\@\@\@P/;
($content, $mtime2) = Download($URL);
if ($content) {
$content =~ s/\n\r/\n/g;
$content =~ s/\r/ /g; # amazing, stray carriage returns
$content =~ s/(\[[A-Z\d\-]+\])\n( - \d\d?\/)/$1$2/g; # bring cosponsorship date onto previous line
$content =~ s/(.)<\/br>/$1\n<\/br>/g;
@content = split(/\n+/, $content);
for my $cline (@content) {
if ($cline =~ /(<br ?\/>)?<a href=[^>]+>(Rep|Sen) ([\w\W]+)<\/a> \[([A-Z\d\-]+)\] - (\d\d?\/\d\d?\/\d\d\d\d)(\(withdrawn - (\d\d?\/\d\d?\/\d\d\d\d)\))?/i) {
my $t = $2;
my $n = $3;
my $s = $4;
my $d = $5;
my $withdrawndate = $7;
$n =~ s/Colordao/Colorado/; # typo
if ($d eq "12/31/1980") { $d = "12/16/1980"; } # they were already out of session
my $d2 = ParseDateTime($d);
$d = ParseTime($d);
if ($d < $INTRODUCED) {
#warn "co-sponsor date $d2 is earlier than introduced date $INTRODUCED2, using introduced date";
$d = $INTRODUCED;
$d2 = $INTRODUCED2;
}
my $i;
if ($cline =~ /FLD004\+\@4\(\(\@1\([^"]+\)\)\+(\d{5})\)/) {
# Starting in 2013, try THOMAS IDs first. More reliable? We're
# only doing historical data now anyway.
my $thomasid = $1;
my @ret = DBSelectFirst(people, [id], ["thomasid='$thomasid'"]);
$i = $ret[0];
} else {
$i = PersonDBGetID(title => $t, name => $n, state => $s, when => $d);
}
if (!defined($i)) {
warn "parsing bill $BILLTYPE$SESSION-$BILLNUMBER: Unknown person: $t, $n, $s on $d2";
$COSPONSORS_MISSING = 1;
}
else {
if (!$cosponsors_seen{$i}) {
# If we've already seen this cosponsor, then it's
# because he rejoined after withdrawing.
push @COSPONSORS, { id => $i, added => $d2, removed => $withdrawndate ? ParseDateTime($withdrawndate) : undef };
$cosponsors_seen{%i} = 1;
}
}
}
}
}
# TITLES
$URL =~ s/\@[\w\W]*$/\@\@\@T/;
($titles, $mtime2) = Download($URL);
if ($titles) {
$titles =~ s/[\n\r]//g;
$titles =~ s/<\/?i>//gi;
$titles =~ s/.*italics indicate a title for a portion of a bill//; # don't get confused by content before, like stuff stuffed into a meta tag
while ($titles =~ m/<li>([\w\W]*?)( as [\w ]*)?:<br\/?>([\w\W]+?)(<p>|<\/ul>|$)/gi) {
my $type = $1;
my $when = $2;
my $ts = $3;
$type =~ s/ title(\(s\))?//i;
$when =~ s/^ as //i;
foreach my $t (split(/<BR\/?>/i, $ts)) {
$t =~ s/<\/?[^>]+>//g;
$t =~ s/ / /g;
$t =~ s/\s*\(identified by CRS\)//gi;
push @TITLES, [lc($type), lc($when), HTMLify($t)];
}
}
}
if (scalar(@TITLES) == 0) { push @TITLES, $backup_title; }
# SUMMARY
my $summarymode = 0;
my $SUMMARY = undef;
$URL =~ s/\@[\w\W]*$/\@\@\@D\&summ2=m\&/;
($content, $mtime2) = Download($URL);
if (!$content) { return; }
$content =~ s/\x1f\x1d//g; # weird characters in HR 545/101
$content =~ s/\n\r/\n/g;
$content =~ s/\r/ /g; # amazing, stray carriage returns
@content = split(/\n+/, $content);
while (scalar(@content) > 0) {
my $cline = shift(@content);
if ($summarymode == 1) {
if ($cline =~ /<HR/i) { $summarymode = 0; next; }
if ($cline =~ /THOMAS Home|<div id="footer">/) { last; }
$cline =~ s/<a[^>]*>([\w\W]*?)<\/a>/$1/ig;
$SUMMARY .= $cline . "\n";
next;
} elsif ($cline =~ /<b><a name="summary">SUMMARY AS OF:<\/a><\/b>/i) {
$summarymode = 1;
}
}
# GET COMMITTEES
$URL = "http://thomas.loc.gov/cgi-bin/bdquery/z?d$SESSION2:$BILLTYPE2$BILLNUMBER:\@\@\@C";
($content, $mtime2) = Download($URL);
if (!$content) { return; }
@content = split(/[\n\r]+/, $content);
foreach $c (@content) {
if ($c =~ /<a href="\/cgi-bin\/bdquery(tr)?\/R\?[^"]+">([\w\W]*)<\/a>\s*<\/td><td width="65\%">([\w\W]+)<\/td><\/tr>/i) {
my $c = $2;
my $r = $3;
$c =~ s/[\\\/]/\-/g;
$c =~ s/ / /g;
$r =~ s/[\\\/]/\-/g;
if (!$c) { next; }
if ($c =~ s/^Subcommittee on \s*([\w\W]*)$/$1/i) {
push @COMMITTEES, [$lastcommittee, $c, $r];
} else {
push @COMMITTEES, [$c, undef, $r];