Michael Bommarito (g0thm0g) wrote in lj_nifty,
Michael Bommarito
g0thm0g
lj_nifty

LJ Time Chart

[update: 2005-05-22 @ 11:26]
I went ahead and wrote an XML-RPC client to process friends only journals, as well as handle requests for full journal distributions. For all of you who requested this, enjoy :)

require_once("XML/RPC.php");

class LJ_Client {
  var $if = null;
  var $user = null;
  var $password = null;
  
  function LJ_Client($user=null, $password=null, $proxy_host=null, $proxy_port=null, $proxy_user=null, $proxy_password=null) {
    $this->user = $user;
    $this->password = $password;
    $this->if = new XML_RPC_Client('/interface/xmlrpc', 'www.livejournal.com', 80, $proxy_host, $proxy_port, $proxy_user, $proxy_password);
  }
  
  function getEvents($n = 50, $before = null) {
    if($before == null) {
        $before = date("Y-m-d H:i:s");
    }
    
    $msg = new XML_RPC_Message('LJ.XMLRPC.getevents', 
        array(XML_RPC_encode(array('username' => $this->user,
          'hpassword' => md5($this->password), 
          'selecttype' => 'lastn', 
          'howmany' => $n,
          'ver' => 1,
          'beforedate' => $before))));
    
     $resp = $this->if->send($msg);
     
     if (!$resp) {
        echo 'Communication error: ' . $this->if->errstr;
        exit;
    }
    
    if (!$resp->faultCode()) {
        $val = $resp->value();
        $data = XML_RPC_decode($val);
        return $data['events'];
    } else {
        /*
         * Display problems that have been gracefully cought and
         * reported by the xmlrpc.php script
         */
        echo '<b style="color:#f00;">';
         echo 'Fault Code: ' . $resp->faultCode() . "\n";
        echo 'Fault Reason: ' . $resp->faultString() . "\n";
        echo '</b>';
    }      
  }
}

$user = $_REQUEST['user'];
$pass = $_REQUEST['password'];

$c = new LJ_Client($user, $pass);

$events = $c->getEvents(50);

while($o = end($events)) {
    $ldate = $o['eventtime'];
    $r = $c->getEvents(50, $ldate);
    if(sizeof($r) == 0) {
        break;
    } else {
        $events = array_merge($events, $r);
    }    
}

$h_dist = array();

foreach ($events as $e) {
  $h = (int)current(split(':', end(split(' ', $e['eventtime']))));
  $h_dist[$h]++;  
}


Hourly Distribution of g0thm0g's Journal Entries (FULL JOURNAL version)

36
13
6
1
1
2
9
16
17
14
12am1am2am3am4am5am6am7am8am9am10am11am
9
12
13
13
15
32
27
25
27
24
33
67
12pm1pm2pm3pm4pm5pm6pm7pm8pm9pm10pm11pm

When do you post?
Username:
Password:
Created by g0thm0g!

[/update]

Originally hacked togther last night in a fit of boredom. Seems to have caught on with the friends page. Try it, but I'm running the server locally, so if it gets too slow/dies, sorry :(

N.B.: Also only works on the last 25 entries, so not a large enough sample to make any cooler observations on. If anyone could chim in with a practical method for retrieving older entries (page-scraping and XML-RPC w/ authentication aside), it would be much appreciated :)


Hourly Distribution of g0thm0g's Posts

3
1
1
3
12am1am2am3am4am5am6am7am8am9am10am11am
1
1
1
1
3
3
2
1
4
12pm1pm2pm3pm4pm5pm6pm7pm8pm9pm10pm11pm

When do you post?
Username:
Created by g0thm0g!


[edit: Updated 07:15 2005/05/20 - Text color problems should be fixed now, as well as a few other minor issues.]
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 54 comments
Previous
← Ctrl ← Alt
Next
Ctrl → Alt →
Previous
← Ctrl ← Alt
Next
Ctrl → Alt →