Created
January 6, 2011 23:37
-
-
Save sansumbrella/768854 to your computer and use it in GitHub Desktop.
Use SimplePie to write twitter rss search results to a file.
This file contains hidden or 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( '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