Created
September 26, 2008 01:24
-
-
Save reid/13002 to your computer and use it in GitHub Desktop.
Parse a Yahoo! Pipe of Twitter feeds to make wordle.net friendly output
This file contains 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 | |
/* twipple.php | |
* Yahoo! Pipes + Twitter + Wordle | |
* | |
* Usage: php twipple.php | pbcopy | |
* ...then paste into wordle.net | |
*/ | |
$pipe_url = 'http://pipes.yahoo.com/pipes/pipe.run?_id=0Dd3hqOG3RGDdbrnbLsjiw&_render=php'; | |
// Run a Yahoo! Pipe to get some Twitter feeds | |
$serialized = file_get_contents($pipe_url); | |
$arr = unserialize($serialized); | |
$items = $arr['value']['items']; | |
foreach ($items as $item) { | |
$c = $item['content']; | |
// Get rid of the Twitter username and trim whitespace | |
$c = explode(':', $c); | |
array_shift($c); | |
$c = implode(':', $c); | |
$c = trim($c); | |
// Remove Twiter @usernames, transform #tag into tag | |
$t = explode(' ', $c); | |
foreach ($t as $k => $word) { | |
if ($word[0] == '@') { | |
unset($t[$k]); | |
continue; | |
} | |
if ($word[0] == '#') { | |
$t[$k] = substr($word, 1); | |
} | |
} | |
$c = implode(' ', $t); | |
echo strtolower($c) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment