Skip to content

Instantly share code, notes, and snippets.

@TrevorBramble
Created October 21, 2009 05:05
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 TrevorBramble/214887 to your computer and use it in GitHub Desktop.
Save TrevorBramble/214887 to your computer and use it in GitHub Desktop.
#!/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