Skip to content

Commit

Permalink
Add a sanity check for missing / excess legislators
Browse files Browse the repository at this point in the history
Toward #32.
  • Loading branch information
waldoj committed Dec 22, 2017
1 parent 89f3a63 commit db328ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
34 changes: 12 additions & 22 deletions utilities/update_legislators.php → cron/legislators.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

# INCLUDES
# Include any files or libraries that are necessary for this specific
# page to function.
include_once('../includes/settings.inc.php');
include_once('../includes/functions.inc.php');

# Connect to the database via PDO.
$db = connect_to_db('pdo');

/*
* Retrieve a list of all active legislators' names and IDs.
*/
$sql = 'SELECT name, chamber, lis_id
FROM representatives
WHERE date_ended IS NULL OR date_ended > now()
ORDER BY chamber ASC';
$stmt = $db->prepare($sql);
$stmt = $dbh->prepare($sql);
$stmt->execute();
$known_legislators = $stmt->fetchAll(PDO::FETCH_OBJ);
foreach ($known_legislators as &$known_legislator)
Expand All @@ -37,7 +25,11 @@
}
}

echo '<p>Loaded ' . count($known_legislators) . ' from local database.</p>';
$log->put('Loaded ' . count($known_legislators) . ' from local database.', 1);
if (count($known_legislators) > 140)
{
$log->put('There are ' . count($known_legislators) . ' legislators in the database—too many.', 5);
}

/*
* Get senators. Their Senate ID (e.g., "S100") is the key, their name is the value.
Expand All @@ -54,7 +46,7 @@
$senators = $tmp;
unset($tmp);

echo '<p>Retrieved ' . count($senators) . ' senators from senate.virginia.gov.</p>';
$log->put('Retrieved ' . count($senators) . ' senators from senate.virginia.gov.', 1);

/*
* Get delegates. Their House ID (e.g., "H0200") is the key, their name is the value.
Expand All @@ -71,7 +63,7 @@
$delegates = $tmp;
unset($tmp);

echo '<p>Retrieved ' . count($delegates) . ' delegates from virginiageneralassembly.gov.</p>';
$log->put('Retrieved ' . count($delegates) . ' delegates from virginiageneralassembly.gov.', 1);

/*
* First see if we have records of any representatives that are not currently in office.
Expand All @@ -88,7 +80,7 @@
{
if (!isset($senators[$id]))
{
echo '<li>Remove Sen. ' . $known_legislator->name . '</li>';
$log->put('Error: Sen. ' . $known_legislator->name . ' is no longer in office, but is still listed in the database.', 5);
}
}

Expand All @@ -99,7 +91,7 @@
{
if (!isset($delegates[$id]))
{
echo '<li>Remove Del. ' . $known_legislator->name . '</li>';
$log->put('Error: Del. ' . $known_legislator->name . ' is no longer in office, but is still listed in the database.', 5);
}
}

Expand All @@ -126,8 +118,7 @@

if ($match == FALSE)
{
echo '<li>Add <a href="http://apps.senate.virginia.gov/Senator/memberpage.php?id='
. $lis_id . '">' . $name . '</a></li>';
$log->put('Senator missing from the database: ' . $name . ' (http://apps.senate.virginia.gov/Senator/memberpage.php?id=' . $lis_id . ')', 6);
}

}
Expand All @@ -150,8 +141,7 @@

if ($match == FALSE)
{
echo '<li>Add <a href="http://virginiageneralassembly.gov/house/members/members.php?id='
. $lis_id . '">' . $name . '</a></li>';
$log->put('Delegate missing from the database: ' . $name . ' (http://virginiageneralassembly.gov/house/members/members.php?id='. $lis_id . ')', 6);
}

}
6 changes: 6 additions & 0 deletions cron/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
require 'cleanup.php';
}

# Check for missing / excess legislators.
if ($type == 'legislators')
{
require 'legislators.php';
}

# Run cache.php, which has a bunch of functions that preemptively load data into the in-memory
# cache.
if (($type == 'all') || ($type == 'cache'))
Expand Down

0 comments on commit db328ae

Please sign in to comment.