TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Pulling my hair out.... (http://www.talkphp.com/general/5149-pulling-my-hair-out.html)

maeltar 12-05-2009 03:18 PM

Pulling my hair out....
 
Ok, I have an issue that I "think" could be filesystem related, trouble is I'm not using php for all parts, am using some php, some python and glueing them together with a bash script !


Overview..
What I am trying to do it create a system that deals with information from the "World of Warcraft Armory"..
The first php file is run as a script, and exports the characters returned to a text file.

First the PHP, that works fine and does excatly what I want it to do...

PHP Code:

<?
class armory {

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

 public 
$query;
 public 
$server;
 public 
$guild;
 public 
$guildie;
 public 
$page;

public function 
__construct $query$server$guild$guildie$page ) {
        
$this->query $query;
        
$this->server $server;
        
$this->guild $guild;
        
$this->guildie $guildie;
        
$this->page $page;
 } 
// end of __construct()

public function pull_xml() {



        
$url 'http://eu.wowarmory.com/guild-info.xml?r=' urlencode($this->server) . '&n=' urlencode($this->guild) . '&p=' $this->page;
        
$ch curl_init();
        
curl_setopt ($chCURLOPT_URL$url);
        
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
        
curl_setopt ($chCURLOPT_CONNECTTIMEOUT15);
        
curl_setopt ($chCURLOPT_USERAGENT,  self::BROWSER);

        
$url_string curl_exec($ch);
        
curl_close($ch);
        return 
simplexml_load_string($url_string);


 } 
// end of pull_xml()

// end class

$xml_obj simplexml_load_string($xml);


$armory = new armory('roster''Khadgar''Aeturnus Recuso'NULLNULL);

$xml $armory->pull_xml();

foreach (
$xml->guildInfo->guild->members->character as $char)
        {
        if( 
$char['level'] ==  '80' )
                {
                echo 
iconv("UTF-8""ISO-8859-1"$char['name']) . "\n";
                }

        }
?>


Now for a touch of BASH and python, this part reads the roster list (created from the above php code) then drags a line out at a time and throws another query at the Warcraft Armoury to get ALL the Achievements for each character listed in the roster file (one name per line). The output from the python script is redirected to a text file, one per character listing all achievements completed or not..


Ok, now this is where I have the problem...

The roster list displays the character names correctly with their funky characters.

http://maeltar.homelinux.net/sandbox...ist_sorted.txt

The problem lays with the file names created by the BASH script, so that I think is filesystem based...

Code:

for member in $(cat ./cache/roster_list_sorted.txt)
        do
                time_start=`date +%s`
                echo Processing $member
                ./achievement_printer.py --eu -r Khadgar -p $member > ./cache/$member.ach
                time_end=`date +%s`
                time_exec=`expr $(( $time_end - $time_start ))`
                echo "$time_exec seconds"
        done

Ok, now this is where I have the problem...

What i would like to do now, is to process the files and create pretty web pages with the data form each file, not a difficult task in any way, apart from the filenames...

Any ideas ? or should I go back to the drawing board and see if I can write something in PHP that will do the job of the python script (The python script is not my work)

I guess am just looking for pointers really...

The files are stored http://maeltar.homelinux.net/sandbox/wow-scripts/cache/

Have a look and see what I mean about the names...

I have a sneaky feeling am going to have to write someting in PHP to do it...

maeltar 12-05-2009 03:19 PM

Oh, and before anyone says it, yes I know the thing is a mess (the server), is just a junk server I use for basic development and testing..

cachepl0x 12-06-2009 06:45 AM

If I am reading this correctly, couldn't you just use a regex to remove any non alphanumeric characters?

http://www.talkphp.com/general/5142-stripping-non-alpha-numeric-characters.html

maeltar 12-06-2009 08:32 AM

No, thats the problem I need the nonalphanumeric characters as they are the player names..

Maybe I would be better off by creating flat file db with 2 columns...

"player name" | "numeric index"

Then I could use that to grab the correct name when i want to display the actual name of the player, that would get around the issue of the filesystem not able to handle the odd charcters..
In fact am thinking about using mysql to store the data in anyway, so just might plan in that function...

cachepl0x 12-06-2009 09:18 AM

Couldn't you use the regex to remove/convert the special characters from the file name, and keep the contents of the file the same? Or is that also not what you're looking for?

Also, you could just use sqlite if it's a small project, and it would also increase portability.

maeltar 12-06-2009 10:35 AM

Never used sqlite, so may use that, would be nice to learn something else while hacking away at this...

Can't really change the file names like that, as each files contains the achievement (completed/uncompleted) information for that player..


All times are GMT. The time now is 11:16 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0