Created
July 26, 2012 19:46
-
-
Save mjburgess/3184097 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
<?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