Split Outfit roster via PSU CSV Export, w/ Local Cache - PlanetSide Universe
PSU Social Facebook Twitter Twitter YouTube Steam TwitchTV
PlanetSide Universe
PSU: Got cat?
Home Forum Chat Wiki Social AGN PS2 Stats
Notices
Go Back   PlanetSide Universe > PlanetSide Discussions > PlanetSide 2 API Discussion

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 2013-04-08, 03:34 PM   [Ignore Me] #1
Elahhez
Corporal
 
Elahhez's Avatar
 
Misc Info
Split Outfit roster via PSU CSV Export, w/ Local Cache


Greetings all,

This is my take on a split roster using the CSV export of found on your outfit page on PSU.

There are 3 entries to edit at the top
  1. CSV Source
  2. Rank to Split
  3. Cache Time

Local files required:
  1. roster.csv, create empty (might make it on its own)
  2. rostertimer.txt, controls the cache time (might make it on its own)

Code is otherwise copy paste, but you can edit it, in any way you wish.

See example here.

Limited support can be given in this thread.

Hope it can come to some use to anyone.

Source
Code:
<?php

// Edit this for the CSV Export found at your outfit page on PSU 
$csv = "http://www.planetside-universe.com/outfit.php?stats=37509488620613138&csv=export";

// Edit this for the secondary rank to split, like recruits. 
$rnksplit = "Recruit/Inactive";

// Time to Cache in seconds
$cache = "3600"; // one hour

 function formatSeconds($mins) {
        $mins = (int)$mins;
        if ( $mins === 0 ) {
            return "<font color='#666666'>No data</font>";
        }
        // variables for holding values
        $hours = 0;
        $days  = 0;
        $weeks = 0;
        // calculations
        if ( $mins >= 60 ) {
            $hours = (int)($mins / 60);
            $mins = $mins % 60;
        }
        if ( $hours >= 24 ) {
            $days = (int)($hours / 24);
            $hours = $hours % 24;
        }
        // format result
        $result = '';
        if ( $days ) {
            $result .= "{$days}d ";
        }
        if ( $hours ) {
            $result .= "{$hours}h ";
        }
        if ( $mins ) {
            $result .= "{$mins}m";
        }
        $result = rtrim($result);
        return $result;
    }


$timer = file("rostertimer.txt");
$offset = time() - $cache;
$timerraw = (time() - $timer[0]) / 60;
$newtime = explode(".", $timerraw);
if($newtime[0] == 1 || $newtime[0] == 0){
	$s = "";
} else {
	$s = "s";
}
if($newtime[0] == 0) {
$newtime[0] = "&lt;1";
}
if($timer[0] < $offset) {

// This bit puts the file

file_put_contents("roster.csv", file_get_contents($csv));

$timer = fopen("rostertimer.txt","w");
file_put_contents("rostertimer.txt", time());
fclose($timer);
$datasave = "This is live data.";
} else {
$datasave = "Data saved ". $newtime[0] ." minute". $s ." ago.";
}




$row = 1;
if (($handle = fopen("roster.csv", "r")) !== FALSE) {

	echo "<br /><font size='3'>Members</font> &nbsp; <font size='1' color='#666666'>". $datasave ."</font>";

echo "<table class='roster' cellpadding=5 cellspacing=0 border=0 width='100%'><tr bgcolor='#111111'><td><font color='#ffffff'><b>BR</b></font></td><td><font color='#ffffff'><b>Name</b></font></td><td><div align='center'><font color='#ffffff'><b>Rank</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Kills/Assists</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Score/Min</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Time Played</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Facilities C/D*</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Member since</b></font></div></td><td><div align='right'><font color='#ffffff'><b>Last Login</b></font></div></td></tr>";

	while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {


	if($data[3] == $rnksplit) {
		
			$recruits[] = array($data[15], $data[1], $data[3], $data[18], $data[21], $data[4], $data[12], $data[10], $data[11], $data[22], $data[23]);

		 $row++;

	} else {



	if($trcng == 0) {
		$trcolor = "#dedede";
		$trcng = 1;	
	} else {
		$trcolor = "#cdcdcd";
		$trcng = 0;
	}
		$num = count($data);
//        echo "<p> $num fields in line $row: <br /></p>\n";
   if($data[1] == "name_first") {
   // do nothing 
   } else {
		echo "<tr bgcolor='". $trcolor ."'>";
		echo "<td class='border'>". $data[15] ."</td>";
		echo "<td class='border'>". $data[1] ."</td>";
		echo "<td class='border'><div align='center'>". $data[3] ."</div></td>";
		echo "<td class='border'><div align='center'>". $data[18] ."/";
		echo "". $data[21] ."</td></div>";
		echo "<td class='border'><div align='center'>". number_format($data[11], 2, '.', '') ."</div></td>";
		echo "<td class='border'><div align='center'>". formatSeconds($data[10]) ."</div></td>";
		echo "<td class='border'><div align='center'>". $data[22] ."/";
		echo "". $data[23] ."</div></td>";
		echo "<td class='border'><div align='center'>". date("jS M. 'y", $data[4]) ."</div></td>";
		echo "<td class='border'><div align='right'>". date("g:ia jS M. 'y", $data[12]) ."</div></td>";

/*		if($data[24] == "0") {
		echo "<td><font color='#bbbbbb'>Offline</font>";
		echo "</td>";
		} else {
		echo "<td><font color='#00FF00'>Online</font>";
		echo "</td>";
		}
*/	

		echo "</tr>";
   }
		     $row++;
	}
    }
	echo "</table>";
	echo "* Facilities that has been <b>C</b>aptured and <b>D</b>efended<br />";
    fclose($handle);
}

echo "<br /><font size='3'>Recruits / Inactive</font> &nbsp; <font size='1' color='#666666'>". $datasave ."</font>";


echo "<table class='roster' cellpadding=5 cellspacing=0 border=0 width='100%'><tr bgcolor='#111111'><td><font color='#ffffff'><b>BR</b></font></td><td><font color='#ffffff'><b>Name</b></font></td><td><div align='center'><font color='#ffffff'><b>Rank</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Kills/Assists</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Score/Min</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Time Played</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Facilities C/D*</b></font></div></td><td><div align='center'><font color='#ffffff'><b>Member since</b></font></div></td><td><div align='right'><font color='#ffffff'><b>Last Login</b></font></div></td></tr>";
	
for($i=0; $i<count($recruits); ++$i) {

	if($trcng == 0) {
		$trcolor = "#dedede";
		$trcng = 1;	
	} else {
		$trcolor = "#cdcdcd";
		$trcng = 0;
	}
		$num = count($data);
//        echo "<p> $num fields in line $row: <br /></p>\n";
   if($data[1] == "name_first") {
   // do nothing 
   } else {
		echo "<tr bgcolor='". $trcolor ."'>";
		echo "<td class='border'>". $recruits[$i][0] ."</td>";
		echo "<td class='border'>". $recruits[$i][1] ."</td>";
		echo "<td class='border'><div align='center'>". $recruits[$i][2] ."</div></td>";
		echo "<td class='border'><div align='center'>". $recruits[$i][3] ."/";
		echo "". $recruits[$i][4] ."</td></div>";
		echo "<td class='border'><div align='center'>". number_format($recruits[$i][8], 2, '.', '') ."</div></td>";
		echo "<td class='border'><div align='center'>". formatSeconds($recruits[$i][7]) ."</div></td>";
		echo "<td class='border'><div align='center'>". $recruits[$i][9] ."/";
		echo "". $recruits[$i][10] ."</div></td>";
		echo "<td class='border'><div align='center'>". date("jS M. 'y", $recruits[$i][5]) ."</div></td>";
		echo "<td class='border'><div align='right'>". date("g:ia jS M. 'y", $recruits[$i][6]) ."</div></td>";
		echo "</tr>";	

}
}
echo "</table>";
echo "* Facilities that has been <b>C</b>aptured and <b>D</b>efended<br />";
echo "Roster imported from <a href='http://www.planetside-universe.com/'>PSU</a>";

?>
-Ela
__________________

Get this or an empire themed dynamic sig with your name on it at http://ps2.gilsweb.com/
Belonging to Long Forgotten Soldiers outfit on Miller, Technology IS Might

Last edited by Elahhez; 2013-04-08 at 03:46 PM.
Elahhez is offline  
 
  PlanetSide Universe > PlanetSide Discussions > PlanetSide 2 API Discussion

Bookmarks

Discord


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:41 AM.

Content © 2002-2013, PlanetSide-Universe.com, All rights reserved.
PlanetSide and the SOE logo are registered trademarks of Sony Online Entertainment Inc. © 2004 Sony Online Entertainment Inc. All rights reserved.
All other trademarks or tradenames are properties of their respective owners.
Powered by vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.