Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example PHP script to generate an RSS feed of a StoryCorps Archives interview search result
<?php
$storycorps_archive_html = file_get_contents( 'https://api.storycorps.me/wp-json/interviews?filter[places]=richmond,indiana' );
$storycorps_archive = json_decode( $storycorps_archive_html, true );
$xml = new SimpleXMLElement('<rss/>');
$xml->addAttribute("version", "2.0");
$channel = $xml->addChild("channel");
$channel->addChild("title", 'Richmond Indiana interviews on StoryCorps' );
$channel->addChild("link", "https://archive.storycorps.org/user/joesmith/interviews/" );
$channel->addChild("description", "Richmond Indiana interviews on StoryCorps");
$channel->addChild("language", "en-us");
foreach ( $storycorps_archive as $interview ) {
$item = $channel->addChild("item");
$item->addChild("link", $interview['url'] );
$interview_date = strtotime( $interview['created_date'] );
$interview_date_for_title = date( 'F j, Y', $interview_date );
$item->addChild("pubDate", date( 'r', $interview_date ) );
if ( ! empty( $interview['additional_participants'] ) && is_array( $interview['additional_participants'] ) ) {
$interview_subjects = array();
foreach ( $interview['additional_participants'] as $participant ) {
if ( 'Joe' === $participant['first_name'] && 'Smith' === $participant['last_name'] ) {
continue;
}
$interview_subjects[] = trim( $participant['first_name'] ) . ' ' . trim( $participant['last_name'] );
}
if ( 0 < count( $interview_subjects ) ) {
$item->addChild("title", sprintf( "StoryCorps interview with %s", implode(', ', $interview_subjects ) ) );
} else {
$item->addChild("title", sprintf( "A %s StoryCorps interview from Richmond, Indiana", $interview_date_for_title ) );
}
} else {
$item->addChild("title", sprintf( "A %s StoryCorps interview from Richmond, Indiana", $interview_date_for_title ) );
}
$item->addChild("description", $interview['description'] );
$mediaGroup = $item->addChild('media:group', '', 'http://search.yahoo.com/mrss/');
$thumbnail = $mediaGroup->addChild( 'media:thumbnail' );
$thumbnail->addAttribute( 'url', $interview['photo'] );
}
$filename = '/home/chris/feeds/www/storycorps-richmond.rss';
$rss_file = fopen( $filename, 'w' ) or die ("Unable to open $filename!" );
fwrite( $rss_file, $xml->asXML() );
fclose( $rss_file );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.