Help reading votes.xml.txt

Discover FAST, a records keeping server control script with a public records system called Dedimania, which will show records from the server on tm-exchange.com

Moderators: Slig, TM-Patrol

Post Reply
Mort
smooth traffic navigator
smooth traffic navigator
Posts: 275
Joined: 16 Jan 2009 10:57
Owned TM-games: TMUF, TMNF
Location: Australia
Contact:

Help reading votes.xml.txt

Post by Mort » 31 Mar 2009 10:49

Greetings,

I've been trying to find a way to parse the votes.xml.txt data into something easily readable, basically a list of the track names and the current "score" each has. I just don't know XML that well, and everything I try involves heaps of messing around to make it readable.

Can anyone give me a tip on what programs or scripts etc will help me out here? I need something that will work on Windows.

Thanks
Mort.

User avatar
Slig
Pit Crew
Pit Crew
Posts: 2124
Joined: 05 Sep 2005 17:51
Owned TM-games: ALL
Location: TraxicoLand (Fr)
Contact:

Re: Help reading votes.xml.txt

Post by Slig » 31 Mar 2009 14:44

Mort wrote:I've been trying to find a way to parse the votes.xml.txt data into something easily readable, basically a list of the track names and the current "score" each has. I just don't know XML that well, and everything I try involves heaps of messing around to make it readable.
this scripts existed for fast3.1, i think that it still works.

Mort
smooth traffic navigator
smooth traffic navigator
Posts: 275
Joined: 16 Jan 2009 10:57
Owned TM-games: TMUF, TMNF
Location: Australia
Contact:

Re: Help reading votes.xml.txt

Post by Mort » 02 Apr 2009 23:38

Brilliant, thanks Slig.

It works great, but a few of our track names have commas in them so I had to tweak the sprintf line to add quotes around the track name data element. I also added a header column just coz I like that sort of thing :)

Code: Select all

<?php

require('includes/xml_parser.php');

$xmldata = file_get_contents('votes.xml.txt');
$data = xml_parse_string($xmldata);

$msg = sprintf("Track Name,Environment,Author,Average,Total,Votes\n");
foreach($data['votes'] as $uid => &$challenge){
	// make a mix of votes of all modes
	$total = 0;
	$count = 0;
	for($mode=0;$mode<5;$mode++){
		if(isset($challenge['Mode.'.$mode]) && isset($challenge['Mode.'.$mode]['Votes'])){
			$total += $challenge['Mode.'.$mode]['VoteTotal']+0;
			$count += $challenge['Mode.'.$mode]['VoteCount']+0;
		}
	}
	if($count>0){
		// make line info for the challenge
		$msg .= sprintf("\"%s\",%s,%s,=%d/%d,%d,%d\n",
										$challenge['Name'],
										$challenge['Environnement'],
										$challenge['Author'],
										$total,$count,
										$total,
										$count
										);
	}
}

file_put_contents('votes.csv',$msg);

?>

Post Reply