Skip to content

Commit

Permalink
Add a fiscal impact statement parser
Browse files Browse the repository at this point in the history
  • Loading branch information
waldoj committed Feb 8, 2024
1 parent dd37a8f commit 4cb51d7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
55 changes: 55 additions & 0 deletions cron/fiscal_impact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
Sometimes there is more than one fiscal impact statement. Sometimes they reflect changes
in the legislation, but sometimes I think they're from multiple agencies?
How to tell the difference between what's an updated FIS vs. an additional one? That is,
what replaces and what supplements?
Do we store the PDF URL? Because the provided filename isn't actually the filename.
Should this be in a new table?
*/

// Get the CSV
$filename = 'FiscalImpactStatements.csv';
if (!file_exists($filename) || !is_readable($filename)) {
exit($filename . ' not found or is not readable');
}
$csv = file($filename);

// Remove the header row
unset($csv[0]);

$fis_data = array_map('str_getcsv', $csv);

// Initialize the array that will store our finished data
$fis = [];

foreach ($fis_data as $statement) {
$bill = strtolower($statement[0]);
$bill = preg_replace('/([a-z]+)(0+)/', '$1', $bill);

$filename = str_replace(strtoupper($bill), '', $statement[1]);
$filename = trim(str_replace('.PDF', '', $filename));

$fis[$bill] = $filename;
}

// Insert the records
foreach ($fis as $bill_number => $fis_id)
{
$sql = 'UPDATE bills
SET impact_statement_id= "' . $fis_id . '"
WHERE number=" ' . $bill_number . '" AND
session_id = ' . SESSION_ID;
$result = mysqli_query($GLOBALS['db'], $sql);
if ($result === false) {
$log->put('Error: Adding a fiscal impact statement for ' . $bill['number'] . ' failed: '
. mysqli_error($GLOBALS['db']), 4);
}
else {
$log->put('Added a fiscal impact statement for ' . $bill['number'] . '.', 1);
}
}
7 changes: 6 additions & 1 deletion cron/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@
require 'checks.php';
}

# Summarize fiscal impact statements
# Retrieve parse fiscal impact statements CSV.
if (($type == 'all') || ($type == 'fiscal_impact')) {
require 'fiscal_impact.php';
}

# Summarize fiscal impact statements.
if (($type == 'all') || ($type == 'summarize_fis')) {
require 'summarize_fis.php';
}
Expand Down
4 changes: 4 additions & 0 deletions deploy/crontab.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
# Updates the sections of the code referred to within each bill.
5,15,25,35,45,55 * * 1-3,10-12 * /usr/bin/php rs-machine/cron/update.php code_sections

# Update the fiscal_impact statements
52 11,13,15,17,19,21 * * * /usr/bin/expect rs-machine/cron/sftp.sh FiscalImpactStatements.csv rs-machine/cron/FiscalImpactStatements.csv
53 11,13,15,17,19,21 * * * /usr/bin/php rs-machine/cron/update.php fiscal_impact

# Re-zip the current year's downloadable bill full-text HTML.
* 3 * * * /usr/bin/zip -rj rs-machine/downloads/bills/2022 rs-machine/downloads/bills/2022

Expand Down

0 comments on commit 4cb51d7

Please sign in to comment.