WarcraftReamls.com
  FAQFAQ    SearchSearch    MemberlistMemberlist    UsergroupsUsergroups   RegisterRegister 
  ProfileProfile    Log in to check your private messagesLog in to check your private messages    Log inLog in 
Some sample guild export code
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    WarcraftRealms.com Forum Index -> WarcraftRealms Developers
View previous topic :: View next topic  
Author Message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Thu Jan 27, 2005 12:24 pm    Post subject: Some sample guild export code Reply with quote

Here is some sample code to get people a little jump start in utilizing the guild export feature. Feel free to use as you like. You should be able to utilize this fairly easily. Just make sure to update the local directory where files should be stored/read and update your guildid and viola, it should work!

Code:
<?php
    //
    //  Rostertest.php
    //
    //  Sample guild export downloader and display
    //  You may use this script as you wish.  This is only some sample code
    //  provided to help get a jumpstart!
    //
    //  Created: 1/27/2005   
    //
    //  Author:  Cooper Sellers aka Rollie - Bloodscalp
    //

    $local_directory = "/";     //  this is the directory where your local files
                                //  will be written to and read from.  Make sure
                                //  you have WRITE priveledges on this directory

    $guild_id        = 33962;   //  get this number from the link posted on the
                                //  guilddisplay.php page
                               


    //
    //  Remember to check the status file so that you are not pulling data
    //  more than once per day
    //
    $localstatusfile = $local_directory . "status.txt";
    $infile = fopen ($localstatusfile, "r");
    $current_timestamp = 0;
    if (!$infile)
    {
        echo "<p>No status file available, assuming this is the first run<br>";
    }
    else
    {
        //  read our status file time
        $buffer = fgets($infile, 4096);

        $current_timestamp = trim( $buffer );

        echo 'Local status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$current_timestamp) . '<br>';
    }
    fclose( $infile );         //  close our local status file
   
    $filename = "http://www.warcraftrealms.com/exports/status.txt";
    $infile = fopen ($filename, "r");   // open remote status file
    if (!$infile)
    {
        echo "<p>Unable to open status file.<br>";
        exit;
    }

    $remote_timestamp = 0;
    if(!feof ($infile))   // only 1 read should be needed for the status file
    {
        $buffer = fgets($infile, 4096);
        $remote_timestamp = trim( $buffer );

        echo 'Remote status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$remote_timestamp) . '<br>';

    }
    fclose( $infile );  //  close the remote status file

    if( $remote_timestamp - $current_timestamp > 86400 ) //  1 day = 60*60*24
    {
        //
        //  We can do a full get
        //

        //  write our new status file
        $outfilename = $local_directory . "status.txt";
        $outfile = fopen($outfilename, "w");
        if( !$outfile )
        {
            echo "<p>Unable to open save file => " . $outfilename . "<br>";
            exit;
        }

        fputs($outfile, $buffer);
        fclose($outfile);

        //
        //  Now get our guild roster file
        //
        $filename = 'http://www.warcraftrealms.com/exports/guildexport.php?guildid=' . $guild_id;
        $infile = fopen ($filename, "r");
        if (!$infile)
        {
            echo "<p>Unable to open remote file.<br>\n";
            exit;
        }

        $outfilename = $local_directory . "guildroster.csv";
        $outfile = fopen($outfilename, "w");
        if( !$outfile )
        {
            echo "<p>Unable to open save file => " . $outfilename . "<br>\n";
            exit;
        }

        while (!feof ($infile))
        {
            $buffer = fgets($infile, 4096);
            fputs($outfile, $buffer);
        }

        fclose($outfile);
        fclose($infile);
    }



    //
    //  Now let's just output our roster as it's given
    //
    $filename = $local_directory . "guildroster.csv";
    $infile = fopen ($filename, "r");
    if (!$infile)
    {
        echo "<p>Unable to open local roster file.<br>";
        exit;
    }

    //  do one read to get the header
    $buffer = fgets($infile, 4096);

    //  read the entries
    echo '<table><tr><th>Name</th><th>Race</th><th>Class</th><th>Level</th><th>Last Seen</th><th>Rank</th></tr>';
    while (!feof ($infile))
    {
        $buffer = fgets($infile, 4096);
        list( $name, $race, $class, $level, $last_seen, $rank ) = explode(",",$buffer);

        echo '<tr><td>' . $name . '</td><td>' . $race . '</td><td>' . $class . '</td><td>' . $level . '</td><td>' . $last_seen . '</td><td>' . $rank . '</td></tr>';
    }
    echo '</table>';

    //  don't forget our credit link =)

    echo "Guild data provided by <a href='http://www.warcraftrealms.com/'>WarcraftRealms.com</a>.";
?>


Feel free to post questions or suggestions! And please post anything you did to make it work better for you! It might just help others too!


Last edited by Rollie on Wed Feb 23, 2005 8:14 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Thu Jan 27, 2005 12:27 pm    Post subject: Reply with quote

You can see this script in action here:

http://www.warcraftrealms.com/rostertest.php

This is for the guild Absynthe on Dragonblight:

http://www.warcraftrealms.com/guilddisplay.php?guildid=6231
Back to top
View user's profile Send private message Visit poster's website
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Thu Jan 27, 2005 4:45 pm    Post subject: Reply with quote

I greatly appreciate the jumpstart it gives me. I have been out of touch with programming for a while now. With my basics in PHP I should be able to utilize this exemple in setting it up for my guild site.

I will make sure to credit warcreaftrealms for the help!
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Thu Jan 27, 2005 5:15 pm    Post subject: Reply with quote

When you get it up and running, drop a link so I can check out your handywork!
Back to top
View user's profile Send private message Visit poster's website
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Thu Jan 27, 2005 5:42 pm    Post subject: Reply with quote

Don't have time to setup a better looking presentation for tonight, but it works great!

http://ironwolves.vempyre.net/archives/2005/01/members_list_fr.php

I had problems getting the $local_directory variable to point to the right folder with the proper autorisations so I just used "./" to make it easier for me.

I included the census.php (which contains your code) into my members.php page so I can easily isolate the code when/if I have to change it.

When I get more time on my hands I will add css information to the code so it displays the information the way I want it to. (which makes me remember I still have to split my various web interface elements into separate modules for an easier time in creating new pages in the future without having to redo all pages each time I change a link in my menus!)

Big thanks again, just looking at your code made me realize I had forgotten so much about php ... I will have to relearn that I guess, in time.

Adding WarcraftRealms link to my main page. Well worth it.

Edit : removed as many spelling errors as I could find on short notice.
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Thu Jan 27, 2005 6:38 pm    Post subject: Reply with quote

Glad to see someone is getting use out of the exports! Lots of folks are downloading, but I haven't seen anyone putting it to any use yet, hehe!

Very cool!
Back to top
View user's profile Send private message Visit poster's website
Shade
Guest







PostPosted: Sat Jan 29, 2005 5:55 pm    Post subject: Reply with quote

I start working on a better template for it utilizing images etc Smile
Back to top
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Tue Feb 01, 2005 12:42 pm    Post subject: Reply with quote

I plan to modify (when I finally stop playing WoW a bit and fix my site instead, hehe) your base code to replace the echo to the page by code that puts the data into a local guild database, which would let ppl view the data a bit like on WarcraftRealms by letting them sort the data by the various fields.

Shade : by images you mean like on the realm where races and classes have their avatar showing?

Related question : race shows as unknown for all members which havn't been on lately (or just havn't been on while a census took place), what causes this?
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Tue Feb 01, 2005 12:59 pm    Post subject: Reply with quote

Race comes up as unknown if the player has only been seen as an offline guild member. The guild info does not tell you the race, only the class, so I have no way of knowing what race that character is until they are seen by an actualy census.
Back to top
View user's profile Send private message Visit poster's website
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Tue Feb 01, 2005 3:26 pm    Post subject: Reply with quote

Somebody asked the same question already, but I can't seem to find the thread (I know, there isnt that many threads, hehe).

Was there a way to purge members who have been kicked out from the guild list taken with census+ from the WarcraftRealms data?

Or will those appear on the roster until they finally login ( maybe never for deleted characters ) and a census is taken while they are online?

If that's the case, I will certainly want to update my site so it imports the guild data into a database, and include a "black list" of names in the script so specified "black list" of names wont get imported into the database (for known characters who are no longuer played and no longuer part of the guild but still shown as members on WarcraftRealms)

Makes me think, I could easily do the same without the database fonction .. by comaparing each entry form the csv file to the black list and if the name appears on the black list it wont be echoed by the script to print on the web page ..

mmm yes .. would do while I get more time to code the database part ...

will try to put that here as soon as I'm done with it. Bugs me to see non-members on my roster.

I guess there is an easy way to use the while fonction in an internal loop inside the main loop that gets each member name from the csv and compare it to each name on the black list and if its any of those it wont be printed to the page ?

I definitively need to redo some reading on those php programming sites Smile

Edit : I wish I hadnt put the the garbage my book of notes about php programming ... Sad
Back to top
View user's profile Send private message
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Tue Feb 01, 2005 4:27 pm    Post subject: Reply with quote

Code:
<?php
    //
    //  Rostertest.php
    //
    //  Sample guild export downloader and display
    //  You may use this script as you wish.  This is only some sample code
    //  provided to help get a jumpstart!
    //
    //  Created: february 1st 2005   
    //
    //  Author:  Cooper Sellers aka Rollie - Bloodscalp
    //  Modifications: Martin Beauvais aka Greytusks - Aggramar
    //
    //  Trying to add a blacklist function to remove unwanted members from the list
    //

    $local_directory = "./";     //  this is the directory where your local files
                                //  will be written to and read from.  Make sure
                                //  you have WRITE priveledges on this directory

    $guild_id        = 33962;   //  get this number from the link posted on the
                                //  guilddisplay.php page
                               


    //
    //  Remember to check the status file so that you are not pulling data
    //  more than once per day
    //
    $localstatusfile = $local_directory . "status.txt";
    $infile = fopen ($localstatusfile, "r");
    $current_timestamp = 0;
    if (!$infile)
    {
        echo "<p>No status file available, assuming this is the first run<br>";
    }
    else
    {
        //  read our status file time
        $buffer = fgets($infile, 4096);

        $current_timestamp = trim( $buffer );

        echo 'Local status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$current_timestamp) . '<br>';
    }
    fclose( $infile );         //  close our local status file
   
    $filename = "http://www.warcraftrealms.com/exports/status.txt";
    $infile = fopen ($filename, "r");   // open remote status file
    if (!$infile)
    {
        echo "<p>Unable to open status file.<br>";
        exit;
    }

    $remote_timestamp = 0;
    if(!feof ($infile))   // only 1 read should be needed for the status file
    {
        $buffer = fgets($infile, 4096);
        $remote_timestamp = trim( $buffer );

        echo 'Remote status file reads : ' . strftime("%m/%d/%y %H:%M:%S",$remote_timestamp) . '<br>';

    }
    fclose( $infile );  //  close the remote status file

    if( $remote_timestamp - $current_timestamp > 86400 ) //  1 day = 60*60*24
    {
        //
        //  We can do a full get
        //

        //  write our new status file
        $outfilename = $local_directory . "status.txt";
        $outfile = fopen($outfilename, "w");
        if( !$outfile )
        {
            echo "<p>Unable to open save file => " . $outfilename . "<br>";
            exit;
        }

        fputs($outfile, $buffer);
        fclose($outfile);

        //
        //  Now get our guild roster file
        //
        $filename = 'http://www.warcraftrealms.com/exports/guildexport.php?guildid=' . $guild_id;
        $infile = fopen ($filename, "r");
        if (!$infile)
        {
            echo "<p>Unable to open remote file.<br>\n";
            exit;
        }

        $outfilename = $local_directory . "guildroster.csv";
        $outfile = fopen($outfilename, "w");
        if( !$outfile )
        {
            echo "<p>Unable to open save file => " . $outfilename . "<br>\n";
            exit;
        }

        while (!feof ($infile))
        {
            $buffer = fgets($infile, 4096);
            fputs($outfile, $buffer);
        }

        fclose($outfile);
        fclose($infile);
    }



    //
    //  Now let's just output our roster as it's given
    //
    $filename = $local_directory . "guildroster.csv";
    $infile = fopen ($filename, "r");

    $blacklist = $local_directory . "blacklist.txt";
    $blackinfile = fopen ($blacklist, "r");

    if (!$infile)
    {
        echo "<p>Unable to open local roster file.<br>";
        exit;
    }

    if (!$blackinfile)
    {
        echo "<p>Unable to open black list file.<br>";
        exit;
    }

    //  do one read to get the header
    $buffer = fgets($infile, 4096);
    $blackbuffer = fgets($blackinfile, 4096);

    //  read the entries
    echo '<table><tr><th>Name</th><th>Race</th><th>Class</th><th>Level</th><th>Last Seen</th><th>Rank</th></tr>';
    while (!feof ($infile))
    {
        $buffer = fgets($infile, 4096);
        list( $name, $race, $class, $level, $last_seen, $rank ) = explode(",",$buffer);

   while (!feof ($blackinfile)) // trying to check each name and print it if not on blacklist and print blacklist if its on for dubugging purposes
   {
        $blackbuffer = fgets($blackinfile, 4096);
             list( $blackname ) = explode(",",$blackbuffer);
        
        if ( $name != $blackname )
        {
      echo '<tr><td>' . $name . '</td><td>' . $race . '</td><td>' . $class . '</td><td>' . $level . '</td><td>' . $last_seen . '</td><td>' . $rank . '</td></tr>';
        }
        elseif ( $name == $blackname )
        {
      echo '<tr><td><b><i>blacklist</i></b><td></tr>';
        }
   }


    }
    echo '</table>';

    //  don't forget our credit link =)

    echo "Guild data provided by <a href='http://www.warcraftrealms.com/'>WarcraftRealms.com</a>.<br>Hugue Thanks to Rollie for starting this script!";
?>


Ok you can see its result : http://ironwolves.vempyre.net/members/census2.php

And compare it to Rollie's posted script : http://ironwolves.vempyre.net/members/census.php

MY skills are rusty, why does it stop after the first name? A problem with the nested while functions?
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Tue Feb 01, 2005 4:41 pm    Post subject: Reply with quote

From first glance, it would appear that the problem is that when you read the first character from the infile, you then read through the entire blacklist file to the end. Now

Code:
while (!feof ($blackinfile))

will always return false so you will not output more than the first group.

The best approach to do what you are trying is to first open your blacklist file and read in all the characters to a list, then read the roster file and check to see if each name is in the list of blacklisted characters.

Are the blacklisted names characters that are no longer in the guild but they still show up on the site as being in the guild?
Back to top
View user's profile Send private message Visit poster's website
Greytusks



Joined: 27 Jan 2005
Posts: 8
Location: Quebec
WR Updates: 20,240
Greytusks WR Profile

PostPosted: Tue Feb 01, 2005 4:51 pm    Post subject: Reply with quote

Rollie wrote:
Are the blacklisted names characters that are no longer in the guild but they still show up on the site as being in the guild?


exact

And good suggestion, thanks

edit :

Code:
    //  do one read to get the header
    $buffer = fgets($infile, 4096);
    $blackbuffer = fgets($blackinfile, 4096);

    // trying to put unwanted names in a list
    while (!feof ($blackinfile))
    {
         $blackbuffer = fgets($blackinfile, 4096);
         list( $blackname ) = explode(",",$blackbuffer);
    }

    //  read the entries from the csv files
    echo '<table><tr><th>Name</th><th>Race</th><th>Class</th><th>Level</th><th>Last Seen</th><th>Rank</th></tr>';
    while (!feof ($infile))
    {
        $buffer = fgets($infile, 4096);
        list( $name, $race, $class, $level, $last_seen, $rank ) = explode(",",$buffer);

    // comparing to the unwanted names
        if ( $name != $blackname )
        {
        echo '<tr><td>' . $name . '</td><td>' . $race . '</td><td>' . $class . '</td><td>' . $level . '</td><td>' . $last_seen . '</td><td>' . $rank . '</td></tr>';
        }
        elseif ( $name == $blackname )
        {
        echo '<tr><td><b><i>blacklist</i></b><td></tr>';
        }
    }
    echo '</table>';


This almost works, exept only the last name of the blacklist is ever considered for the comparisons ... (does it show I barely remember how these functions work? hehe)

if you check the above census2.php link, you will now see one name is listed as blacklist. The blacklist.txt contained 4 names, and the only one that got blacklisted was the last. Thanks for your help on this, helps me refresh my skills !


Last edited by Greytusks on Tue Feb 01, 2005 5:12 pm; edited 3 times in total
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Tue Feb 01, 2005 5:06 pm    Post subject: Reply with quote

Ah, okay, hopefully this will be resolved soon. I had something in place to fix this but it ended up causing other problems. I'll get back to it and see what I can do.
Back to top
View user's profile Send private message Visit poster's website
Khael



Joined: 05 Feb 2005
Posts: 13

WR Updates: 0
Khael WR Profile

PostPosted: Sat Feb 05, 2005 6:33 am    Post subject: Reply with quote

Harro Rollie,

Great site you got here. I am really happy with the convenience it lends me and other guild webmasters Wink

My code basicly looks like this:

Code:
$csv = file_get_contents("http://www.warcraftrealms.com/exports/guildexport.php?guildid=52794");
$csv = explode("\n",$csv);


So now I have an array with each char in my guild, and I use that for whatever I want to do. It is going to be on our webpage - looking something like this:

http://www.guildofsun.com/Web/Site/Games
_________________
Khael[SUN]
GUILD OF SUN - slaying carebears since 1873
Webmaster: http://www.guildofsun.com
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Sat Feb 05, 2005 10:45 am    Post subject: Reply with quote

You need to download the file locally and parse it on your end instead of pulling the file each time the page is viewed.

From the exports page:


Quote:
#5 You must code your web site or application to only download the CSV file when there is a new one available. There is no advantage to be gained from downloading every time you need to access the data and it will keep our bandwidth usage figures down. You can use the status files (see below) to find out if a new version of the file is available.


Quote:
There is also a status file available, that allows you to get the date when the files were last generated (in UNIX timestamp format):

http://www.warcraftrealms.com/exports/status.txt


Essentially, I would much rather you to only pull a version once a day instead of pulling a version each time the page is accessed.

Your site looks great though!
Back to top
View user's profile Send private message Visit poster's website
Guest








PostPosted: Sat Feb 05, 2005 1:10 pm    Post subject: Reply with quote

Im running a cron script that fetches this every hour, is that ok?

Its not that much bandwidth once per hour =P
Back to top
Khael



Joined: 05 Feb 2005
Posts: 13

WR Updates: 0
Khael WR Profile

PostPosted: Sat Feb 05, 2005 1:12 pm    Post subject: Reply with quote

Oops that was me. I think you update per hour, and as far as I can see, you only save chars that are in game when you export.

So if I run this only once per day, I would miss out on alot of char updates. If you insist, I will check the date in that date file you produce of course, but this will only save minimal bandwidth, and only if you do not update every hour.
_________________
Khael[SUN]
GUILD OF SUN - slaying carebears since 1873
Webmaster: http://www.guildofsun.com
Back to top
View user's profile Send private message
Rollie
Site Admin


Joined: 28 Nov 2004
Posts: 5374
Location: Austin, TX
WR Updates: 480,131
Rollie WR Profile

PostPosted: Sat Feb 05, 2005 6:35 pm    Post subject: Reply with quote

The database information is updated once per hour.

You wouldn't be losing out on any information if you only pulled the file once per day. You get a full listing every time. It would only matter if you had a dynamically changing guild roster (by the hour). I would bet that your guild roster doesn't change that often though.

If you are running a cron job, then it would be a cinch to set it once per day instead of once per hour. Thanks =)

Granted, guild exports are not that big, but it is still unnecessarily spent bandwidth and bandwidth isn't cheap =)
Back to top
View user's profile Send private message Visit poster's website
Khael



Joined: 05 Feb 2005
Posts: 13

WR Updates: 0
Khael WR Profile

PostPosted: Sat Feb 05, 2005 6:46 pm    Post subject: Reply with quote

Ok Rollie, I will take your word for it and change the cron job to run daily instead of course Very Happy

A guildmate told me you are using CensusPlus addon for WoW that does a /who S U N request before export and therefore doesn't list any offline members. Is this entirely wrong?

The reason I am saying this is because the list I have currently at http://www.guildofsun.com/Web/Site/Games has not got all our chars in it, only the ones that have played recently.
_________________
Khael[SUN]
GUILD OF SUN - slaying carebears since 1873
Webmaster: http://www.guildofsun.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    WarcraftRealms.com Forum Index -> WarcraftRealms Developers All times are GMT - 6 Hours
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
WarcraftRealms.com  


Powered by phpBB © 2001, 2005 phpBB Group