views:

75

answers:

2

I'd like to be able to run a script that parsed through the twitter page and compiled a list of tweets for a given time period - one week to be more exact. Ideally it should return the results as a html list that could then be posted in a blog. Like here:

http://www.perezfox.com/2009/07/12/the-week-in-tweet-for-2009-07-12/

I'm sure there's a script out there that could do it, unless the guy does it manually (that would be a big pain!). If there is such a script forgive my ignorance.

Thanks.

+3  A: 

Use the Twitter search API. For instance, this query returns my tweets between 2009-07-10 and 2009-07-17:

http://search.twitter.com/search.atom?q=from:tormodfj&since=2009-07-10&until=2009-07-17

Tormod Fjeldskår
Perfect. Thanks!
different
+1  A: 

For anyone that's interested, I hacked together a quick PHP parser that will take the XML output of the above feed and turn it into a nice list. It's sensible if you post a lot of tweets to use the rpp parameter, so that your feed doesn't get clipped at 15. The maximum limit is 100. So by sticking this url into NetNewsWire (or equivalent feed reader):

http://search.twitter.com/search.atom?q=from:yourTwitterAccountHere&since=2009-07-13&until=2009-07-19&rpp=100

and exporting the xml to a hard file, you can use this script:

<?php
$date = "";
$in = 'links.xml'; //tweets
file_exists($in) ? $xml = simplexml_load_file($in) : die ('Failed to open xml data.');
foreach($xml->entry as $item)
{
    $newdate = date("dS F", strtotime($item->published));
    if ($date == "")
    {
     echo "<h2>$newdate</h2>\n<ul>\n";
    }
    elseif ($newdate != $date)
    {
     echo "</ul>\n<h2>$newdate</h2>\n<ul>\n";
    }
    echo "<li>\n<p>" . $item->content ." <a href=\"" . $item->link['href'] . "\">*</a></p>\n</li>\n";
    $date = $newdate;
}
echo "</ul>\n";
?>
different