Dienstag, 8. Februar 2011

Whew.

So im finally trying to get some sleep.

ive managed to make my arduino tweet. hooooray ;)
and now im in the process of coding a php parser which parses the result of a twitter api search for @twitduin0 on the whole twitter network , to gather all the commands that people are trying to send to the arduino.

unfortunately ive been sitting here for like 20minutes and the f*** search api wont index my new tweet. so i think i have to find a workaround for the time issue, i cant wait 20 mins to make my table switch colors. i want it fast , as fast as the speed of light, daaaaaaaaaamn.

so heres my little php code that i have. im just posting so i can read it at work tomorrow.errrrr.

twit.php
=========
getTweets();
foreach ($tweets as $tweet) {
echo '

' . $tweet['date'] . ' x ' . $tweet['time'] . ' x ' . $tweet['user'] . ' x ' . $tweet['command'] . ' x ' . $tweet['message'] . '

';
}
?>

libTwit.php
===========
doc = new DOMDocument();
$this->tweets = array();
if ($this->doc->load('http://search.twitter.com/search.atom?q=%40twitduin0&&rpp=1')) {
$i = 0;
foreach ($this->doc->getElementsByTagName('entry') as $node) {
$tweet = array(date => $this->getDate($node), time => $this->getTime($node), user => $this->getUser($node), command => $this->getCommand($node), message => $this->getMessage($node));
$this->tweets[$i] = $tweet;
//if ($i == 0) $this->userLink = $node->getElementsByTagName('link')->item(0)->nodeValue;
$i++;
}
}
}

private function getDate($node) {
$tweet = $node->getElementsByTagName('published')->item(0)->nodeValue;
$DATE_ARR = explode("T",$tweet);

return $DATE_ARR[0];
}

private function getTime($node) {
$tweet = $node->getElementsByTagName('published')->item(0)->nodeValue;
$TIME_ARR = explode("T",$tweet);

return $TIME_ARR[1];
}


private function getUser($node) {
$tweet = $node->getElementsByTagName('name')->item(0)->nodeValue;
$USER_ARR = explode(" ",$tweet);
return $USER_ARR[0];
}


private function getCommand($node) {
$tweet = $node->getElementsByTagName('title')->item(0)->nodeValue;
$CMD_ARR = explode(" ",$tweet);
return $CMD_ARR[1];
}

private function getMessage($node) {
$tweet = $node->getElementsByTagName('title')->item(0)->nodeValue;

$tweet = "@twitduin0 #led2 must turn on ;)";
$tweet = str_replace("@twitduin0", "", $tweet);
$tweet = explode(" ", $tweet);
$tweet = implode(",", $tweet); //back into a comma seperated string, so split off the first stuff...

//$res = count($tweet);

return $tweet;
}

public function getTweets() {
return $this->tweets;
}

public function getLink($msg) {
return '' . $msg . '';
}

}

?>

Keine Kommentare:

Kommentar veröffentlichen