Skip to content

Commit

Permalink
Figure out the committee ID
Browse files Browse the repository at this point in the history
Toward #33 and #59.
  • Loading branch information
waldoj committed Jan 26, 2018
1 parent 1328000 commit 974265c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions bin/save_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,55 @@
*/
$metadata = json_decode(file_get_contents($video_dir . 'metadata.json'));

/*
* Identify the committee ID for this video.
*/
if ($metadata->type == 'committee')
{

/*
* First, get a list of all committees' names and IDs.
*/
$sql = 'SELECT id, name
FROM committees
WHERE parent_id IS NULL
AND chamber = "' . $metadata->chamber . '"';
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0)
{

$committees = array();
while ($committee = mysql_fetch_array($result))
{
$committees[] = $committee;
}

$shortest = -1;
foreach ($committees as $id => $name)
{

$distance = levenshtein($metadata->committee, $name);
if ($distance === 0)
{
$closest = $id;
$shortest = 0;
break;
}

elseif ($distance <= $shortest || $shortest < 0)
{
$closest = $id;
$shortest = $distance;
}

}

$metadata->committee_id = $closest;

}

}

/*
* Instantiate the video class
*/
Expand Down Expand Up @@ -71,6 +120,10 @@
$file['type'] = 'video';
$file['title'] = ucfirst($file['chamber']) . ' Video';
$file['capture_directory'] = '/video/' . $metadata->chamber . '/floor/' . $metadata->date .'/';
if (!empty($metadata->committee_id))
{
$file['committee_id'] = $metadata->committee_id;
}

/*
* Store this record in the database.
Expand Down

0 comments on commit 974265c

Please sign in to comment.