Created
October 21, 2009 05:05
-
-
Save TrevorBramble/214887 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/php | |
<?php | |
if (! isset($argv[1])) | |
exit("Provide a Twitter screen name\n"); | |
else | |
$screen_name = $argv[1]; | |
$file = $screen_name.'_tweets.txt'; | |
$fh = fopen($file,'a'); | |
$url = "http://twitter.com/statuses/user_timeline.xml?". | |
"screen_name={$screen_name}&count=200&page="; | |
$iterator = 1; | |
$brake = false; | |
do { | |
$xml = @simplexml_load_file($url.$iterator); | |
if (! $xml) | |
exit("Couldn't load ". ($iterator > 1 ? 'more ' : 'any ') ."tweets.\n"); | |
foreach ( $xml->children() as $child ) | |
fwrite($fh, serialize($child)."\n"); | |
$iterator++; | |
if ( count($xml->children()) < 200 ) $brake = true; | |
} while ( !$brake ); | |
fclose($fh); | |
echo "Wrote as many tweets as I could to {$file}.\n"; | |
if ( filesize($file) == 0 ) unlink($file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment