SecondLife Transaction History - Take 2
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

i need a script / program written that will run as a cronjob (or scheduled task in windows) to download my transaction history for date a to date b, the data needs to be downloaded to an xml file..

Accepted Languages
PHP
Perl
C#
C/C++

if you have any questions let me know, but it should be fairly straight forward i would think.

Christopher, the HTML is all protected by https i wouldn't have the slighest idea of how to obtain it for you, however it is free to sign up for an account, i am aware that the history is only kept for a short period of time, which is exactly why i need this software, so i can retain a long-term copy of my transaction history for refrence purposes...
dvsxutact almost 7 years ago
It would be done with an encapsulated browser. I don't have the time to create an account.
Christopher almost 7 years ago
At any rate, Copy and Paste should probably be your friends here. Any HTML stripper will become obsolete within several months, when the website is updated.
Christopher almost 7 years ago
@dvsxutact Please tell me if the script works for you or not, thanks!
alex almost 7 years ago
awarded to Wikimedia
Tags
java
PHP

Crowdsource coding tasks.

1 Solution


This script uses some code from here. You NEED cURL for this script to work.

<?php
    // Set login details
    $username = 'username'; 
    $password = 'password';
    // Set Dates
        $m2 = "10";     // Start Month
        $d2 = "07";     // Start Day
        $y2 = "2012";   // Start Year
        $m1 = "10";     // End Month
        $d1 = "05";     // End Day
        $y1 = "2012";   // End Day

function update_cookie($cookie,$newcookie) {
    $x = explode(";",$cookie);
    $n = Array();
    $returncookie="";
    foreach($x as $y) {
        $z=explode("=",$y);
        $n[$z[0]]=$z[1];
    }

    $x=explode(";",$newcookie);
    foreach($x as $y) {
        $z=explode("=",$y);
        $n[$z[0]]=$z[1];
    }
    reset($n);
    for($a=0;$a<count($n);$a++) {
        $returncookie.=key($n)."=".$n[key($n)].";";
        next($n);
    }
    return $returncookie;
}
function get_params($c)
{
    preg_match_all('/type\="hidden" name\="([^"]+)" value\="([^"]+)"/',$c,$regs, PREG_SET_ORDER);
    $params=Array();
    foreach ($regs as $r) 
        $params[$r[1]]=$r[2];

    return $params;
}
/**
 * Send a POST requst using cURL
 * @param string $url to request
 * @param array $post values to send
 * @param array $options for cURL
 * @return string
 */
function curl_post_head($url, array $post = NULL, array $options = array())
{
    $defaults = array(
        CURLOPT_POST => 1,
        CURLOPT_HEADER => 1,
        CURLOPT_URL => $url,
        CURLOPT_FRESH_CONNECT => 1,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FORBID_REUSE => 1,
        CURLOPT_TIMEOUT => 4,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_CAINFO =>  getcwd()."/cacert.pem",
        CURLOPT_POSTFIELDS => http_build_query($post)
    );

    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if( ! $result = curl_exec($ch))
    {
        trigger_error(curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
function curl_post($url, array $post = NULL, array $options = array())
{
    $defaults = array(
        CURLOPT_POST => 1,
        CURLOPT_HEADER => 0,
        CURLOPT_URL => $url,
        CURLOPT_FRESH_CONNECT => 1,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FORBID_REUSE => 1,
        CURLOPT_TIMEOUT => 4,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_CAINFO =>  getcwd()."/cacert.pem",
        CURLOPT_POSTFIELDS => http_build_query($post)
    );

    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if( ! $result = curl_exec($ch))
    {
        trigger_error(curl_error($ch));
    }
    curl_close($ch);
    return $result;
}

/**
 * Send a GET requst using cURL
 * @param string $url to request
 * @param array $get values to send
 * @param array $options for cURL
 * @return string
 */

function curl_get($url, array $get = NULL, array $options = array())
{   
    $defaults = array(
        CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
        CURLOPT_HEADER => 0,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_CAINFO =>  getcwd()."/cacert.pem",
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 4
    );

    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if( ! $result = curl_exec($ch))
    {
        trigger_error(curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
function curl_get_head($url, array $get = NULL, array $options = array())
{   
    $defaults = array(
        CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
        CURLOPT_HEADER => 1,
        CURLOPT_SSL_VERIFYPEER => true,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_CAINFO =>  getcwd()."/cacert.pem",
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_TIMEOUT => 4
    );

    $ch = curl_init();
    curl_setopt_array($ch, ($options + $defaults));
    if(!$result = curl_exec($ch))
    {
        trigger_error(curl_error($ch));
    }
    curl_close($ch);
    return $result;
}

    $url = "https://id.secondlife.com/openid/loginsubmit";
    $c = curl_post_head($url,
    Array(
        "username" => $username,
        "password" => $password,
        "Submit" => '',
        "return_to" => "https://secondlife.com/auth/oid_return.php?redirect=https%3A%2F%2Fsecondlife.com%2Findex.php",
        "previous_language" => 'en_US',
        "language" => 'en_US',
        "show_join" => 'True'
        )
    );
    $cookie = "";
    if(preg_match("/Set-Cookie: +(.+)/",$c,$regs))$cookie=update_cookie($cookie,$regs[1]);

    preg_match("/Location: +(.+)/", $c, $regs);
    $location = $regs[1];
    $c = curl_get_head($location, Array(), Array(CURLOPT_COOKIE => $cookie));

    if(preg_match("/Set-Cookie: +(.+)/",$c,$regs))$cookie=update_cookie($cookie,$regs[1]);
    preg_match("/Location: +(.+)/",$c,$regs);
    $location=$regs[1];
    $c=curl_get_head($location,
        Array(),
        Array(CURLOPT_COOKIE=>$cookie)
        );
    $params=get_params($c);

    if(preg_match("/Set-Cookie: +(.+)/",$c,$regs))$cookie=update_cookie($cookie,$regs[1]);

    $location="https://id.secondlife.com/openid/openidserver";
    $c=curl_post_head($location,$params,Array(CURLOPT_COOKIE=>$cookie));

    preg_match("/Location: +(.+)/",$c,$regs);
    $location=$regs[1];
    $c=curl_get_head($location,Array(),
        Array(CURLOPT_COOKIE=>$cookie)
        );
    if(preg_match("/Set-Cookie: +(.+)/",$c,$regs))$cookie=update_cookie($cookie,$regs[1]);

    $location = "https://secondlife.com/my/account/download_transactions.php?date_start=".$y1."-".$m1."-".$d1."&date_end=".$y2."-".$m2."-".$d2."&include_zero=yes&lang=en&submit=View++%28up+to+500%29&download_xml=Download+XML";
    $c = curl_get($location,
            Array(),
            Array(CURLOPT_COOKIE => $cookie)
        );

    $filename = "transactions_".$y2."-".$m2."-".$d2."_".$y1."-".$m1."-".$d1.".xml";
    $fh = fopen($filename, "w");
    fwrite($fh, $c);
    fclose($fh);
?>

Notes

Script will save to a file in the same directory named like transactions_2012-10-07_2012-10-05.xml depending on the dates selected.

Reminder

If you are getting an error for the fopen or fclose please check your PHP file write/create permissions.

Enjoy!