Kastang Ramblings of a Geek

13Jan/118

WoW Roster PHP Class

I am working on a PHP Class called RosterAPI that will parse the WoW Armory without XML Files. Unlike my previous two posts (Part 1 and Part 2), the information for each character can be pulled through get methods. Also included in RosterAPI are guild specific functions not included in my previous posts.

The following methods are currently included:

Character Specific:
* getLevel()
* getGender()
* getClass()
* getRace()
* getAchievementPoints()
* getProfessions(): Returns an associative array containing the name and value of each profession.
* getTalents(): Returns an associative array containing the name and value of each talent tree.
* getStat($stat): Please view the comment header of the getStat() function for a list of valid $stats.

Guild Specific:
* getGuildMembers($rank): If $rank is true, an associative array containing guild names and ranks will be returned. If $rank is false, an array will be returned containing all names in the guild.
* getTopWeeklyContributers(): Returns an array of the Top 5 Weekly Contributers in the guild.
* getGuildPerks(): Returns an array of the perks a guild currently has.

UPDATE:

I have received several emails with suggestions over the past week. In addition to everything listed above, my RosterAPI will also:

*getItems: Returns an Associative Array that will return every item equipped on a character along with the Item Level, Enchants, and Gems.
*getStatistics: Given a specific Statistic (ex: Number of deaths), the value of the statistic will be returned.

The code can be obtained via GitHub. While it is still a work in progress, it should be stable enough for personal use. This class is being used to power the backend of the We Know Roster. Please read the README file along with the example.php file for a brief introduction on how to use the class. I recommend reading the comments above each function in RosterAPI to understand what exactly will be returned (especially with those functions that return associative arrays).

Update #2

The Roster API now returns Glyphs for each character.

EDIT #2:

By request in the comments, here is a Paypal Donate button:


4Dec/100

Using Python to Parse WoW Server XML.

THIS CODE IS OBSOLETE. Blizzard changed the way information can be grabbed from their servers. Please view my PHP Class which will work.

The below Python script will parse the WoW Server XML file and return status, type, name, and load about a specified WoW Server. It also stores the Server XML file into a cache.txt file so constant requests to the script will not result in an IP ban on Blizzards servers.

Python 2.6+ must be used for this script to function correctly. It will work out of the box with no third party libraries required.

Please change the SERVER_NAME (on line 32) variable to your servers name.

#!/usr/bin/python
 
"""
Author: Josh Grochowski (Kastang)
 
This script will parse the WoW Server Status XML file and return
information about a specified server. This Python script works
for me, but it may not work for you. Use this script at your
own risk. 
 
Python 2.6+ must be used.
"""
 
"""
The below four lines assume this script will be loaded onto a
webserver. If you are planning to run this script in a CLI
enviornment, feel free to remove the below four lines of code.
"""
import cgitb
cgitb.enable()
print "Content-Type: text/html;charset=utf-8"
print
 
#Imports
from xml.etree.ElementTree import parse
import urllib, os, time
 
#WoW Server Status Path
WOW_XML = "http://www.worldofwarcraft.com/realmstatus/status.xml"
 
#Change SERVER_NAME to the your server.
SERVER_NAME = "Eitrigg"
 
#Display information for the Realm information.
rStatus = ["Offline", "Online"]
rType = ["", "PVE", "PVP", "RP", "RP PVP"]
rLoad = ["", "Low", "Medium", "High"]
 
#Modification time of the cache file.
modTime =  os.stat("cache.txt").st_mtime
 
#Current system time.
currTime =  time.time()
 
"""
If this function is called, the cache file will be
updated with the newest information from the WoW
Server Status XML file.
"""
def updateCache():
    cache = open("cache.txt", "w")
    cache.writelines(urllib.urlopen(WOW_XML))
 
"""
Given a Realm name and XML file, it will find the
XML string containing information about the specified
Realm and return it to the requesting function.
"""
def findRealm(realm, xml):
        for l in xml.findall('rs/r'):
                if l.get('n') == realm:
                        return l
 
        return False
 
#Displays information about the specified Server.
def printOutput(server):
    print "Realm Name: " + server.get('n')
    print "Realm Type: " + rType[int(server.get('t'))]
    print "Realm Status: " + rStatus[int(server.get('s'))]
    print "Realm Load: " + rLoad[int(server.get('l'))]
 
"""
If the cache file has not been updated for 10 minutes,
it will be updated. Otherwise, the existing file will
be used to find current information about the specified
realm. 
 
If the specified Realm is not a valid WoW Realm, nothing
will be returned. 
 
"""
def main():
    if (currTime - modTime) > 600:
        updateCache()
 
    xml = parse("cache.txt").getroot()
    server = findRealm(SERVER_NAME, xml)
 
    if server != False:
        printOutput(server)
 
if __name__ == "__main__":
    main()

A sample output can be seen below:

# python realmstatus.py
Realm Name: Eitrigg
Realm Type: PVE
Realm Status: Online
Realm Load: High
Tagged as: , , No Comments