Skip to content

Instantly share code, notes, and snippets.

@mjburgess
Created July 26, 2012 19:46
Show Gist options
  • Save mjburgess/3184097 to your computer and use it in GitHub Desktop.
Save mjburgess/3184097 to your computer and use it in GitHub Desktop.
<?php
class Message {
private $text;
private $timestamp;
private $formatter;
public function __construct( $text, $timestamp, $formatter ) {
$this->text = $text;
$this->timestamp = $timestamp;
}
public function __toString() {
$msg = $this->formatter->format( $this->text, $this->timestamp );
return $msg;
}
}
class MessageFormatter {
private $format;
public function __construct( $fmt ) {
$this->format = $fmt;
}
public function format() {
return vsprintf($this->fmt, func_get_args() );
}
}
if ( !isset( $argv[ 1 ] ) ) {
die();
}
$username = $argv[ 1 ];
$tweets = json_decode(
file_get_contents( 'https://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . $username )
);
$fp = fopen( $username . '.txt', 'w' );
foreach ( $tweets as $tweet ) {
$msg = new Message( $tweet->text, $tweet->created_at );
fwrite( $fp, $msg . "\n" );
}
fclose( $fp );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment