Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Created January 6, 2011 23:37
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 sansumbrella/768854 to your computer and use it in GitHub Desktop.
Save sansumbrella/768854 to your computer and use it in GitHub Desktop.
Use SimplePie to write twitter rss search results to a file.
<?php
include( 'simplepie.php' );
$sourceURL = 'feed://search.twitter.com/search.atom?q=+%22i+am+here+now%22&lang=all&rpp=100';
$feed = new SimplePie();
$feed->set_feed_url($sourceURL);
$feed->set_timeout(10);
$feed->enable_cache(true);
$feed->init();
$results = $feed->get_items( 0, 50 );
// for debugging:
// echo "<h1>Feed: $feed</h1>";
// echo "<h1>results: ". count($results) ."</h1>";
// echo "<h1>Now writing background:</h1>";
$file = fopen("tweets/aggregate.txt", 'a+');
if($file)
{
$filecontents = file_get_contents("tweets/aggregate.txt");
$newstuff = "";
$count = 0;
foreach( $results as $tweet ){
$content = str_ireplace( "I am here now", "<em>I am here now</em>", $tweet->get_title() );
if( substr_count( $filecontents, $content ) == 0 )
{
$newstuff .= ($content."\n");
$count++;
}
}
fwrite($file, $newstuff);
fclose($file);
echo "<div>Added $count lines.</div>\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment