Skip to content

Instantly share code, notes, and snippets.

@eriklincoln
Created May 30, 2012 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eriklincoln/2836416 to your computer and use it in GitHub Desktop.
Save eriklincoln/2836416 to your computer and use it in GitHub Desktop.
OpenSecrets API call
$pacs = array(
'Priorities USA Action'=>'C00495861',
'Restore Our Future'=>'C00490045',
'Citizens for a Working America'=>'C00488767',
'Revolution'=>'C00499335',
'Endorse Liberty'=>'C00508002',
'Santa Rita'=>'C00508721',
'Winning Our Future'=>'C00507525',
'Strong America Now'=>'C00505081',
'Red, White and Blue Fund'=>'C00503417',
'Leaders for Families'=>'C00508317',
);
/*
*
* Add IDs to the $committees variables and field you want displayed to $fields
*
*/
$committees = array($pacs['Restore Our Future']);
$fields = array('totalrcpts','total_outside','demfor', 'demagnst', 'repubfor', 'repubagnst', 'updated');
/*
*
* Put this where you want the data displayed
*
*/
$data = json_decode(file_get_contents('http://node-apps.iwatchnews.org/2012/02/superpacs/fetchdata?cmteid='.urlencode(implode(',', $committees)).'&showheaders=true&hidezero=true&fields='.urlencode(implode(',', $fields))), TRUE);
foreach($data as &$record) {
foreach($record as $key=>&$field) {
if(preg_match ('/\#/', $key)==TRUE) continue;
if($key=='updated') {
$field['data'] = DateTime::createFromFormat('U', round($field['data']*.001), new DateTimeZone('America/New_York'));
$field['data']->setTimeZone(new DateTimeZone('America/New_York'));
$field['#markup'] = $field['data']->format('l, F j, Y, g:i a T');
unset($field['data']);
}
}
}
print render($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment