Created
September 12, 2012 21:30
-
-
Save benbalter/3710069 to your computer and use it in GitHub Desktop.
JSON feed of president's daily (public) schedule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include '../wp-load.php'; | |
$url = 'http://www.whitehouse.gov/schedule/president/feed'; | |
$terms_blacklist = array( | |
'president', | |
'vice president', | |
'first lady', | |
); | |
$feed = fetch_feed( $url ); | |
if ( is_wp_error( $feed ) ) | |
die( 'err' ); | |
$events = array(); | |
foreach ( $feed->get_items() as $item ) { | |
$html = $item->get_description(); | |
$title = $item->get_title(); | |
preg_match( '#Date: </div>\s*\<span>(.*)?</span>#is', $item->get_description(), $matches ); | |
//sorry about this, needs to be redone... | |
$matches = $matches[1]; | |
$date_array = explode( ', ', $matches ); | |
$date_shard = explode( ' - ', $date_array[2] ); | |
unset( $date_array[2] ); | |
$date_array = array_merge( $date_array, $date_shard ); | |
$datetime = $date_array[1] . ' ' . $date_array[2] . ' ' . $date_array[3]; | |
$date = strtotime( $datetime ); | |
$categories = array(); | |
foreach ( $item->get_categories() as $category ) { | |
if ( in_array( strtolower( $category->term ), $terms_blacklist ) ) | |
continue; | |
$categories[] = $category->term ; | |
} | |
$location = implode( ' ', $categories ); | |
if ( $location == '' ) | |
continue; | |
$event = array( | |
'title' => $title, | |
'date' => $date, | |
'location' => $location, | |
); | |
$events[] = (object) $event; | |
} | |
header('Content-type: application/json'); | |
echo json_encode( $events ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment