pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

kahrn private pastebin - collaborative debugging tool What's a private pastebin?


Posted by kahrn on Sun 28 Sep 17:39 (modification of post by kahrn view diff)
report abuse | download | new post

  1. """
  2. bf2xml.py 0.1
  3.    Ricky Hewitt <kahrny@gmail.com>
  4.    Part of the xbot irc bot.
  5.    
  6.    This script is able to display BF2 server information by
  7.    obtaining and parsing an XML file.
  8.    Relies on game-monitor.com (for now).
  9.    
  10.    TODO: Add Current Map (limited due to limitations of XML feed)
  11. """
  12.  
  13. import urllib
  14. from xml.dom import minidom
  15.  
  16. def get_server_info(HOST="74.53.113.68:16567"):
  17.     """Retrieve information for a given IP address (e.g. 127.0.0.1:16567).
  18.       Output is in the form of a list."""
  19.     HOST_URL = 'http://module.game-monitor.com/%s/data/server.xml' % (HOST)
  20.    
  21.     dom = minidom.parse(urllib.urlopen(HOST_URL))
  22.     for node in dom.getElementsByTagName('ip'):
  23.         server_ip = node.firstChild.data
  24.     for node in dom.getElementsByTagName('port'):
  25.         server_port = node.firstChild.data
  26.        
  27.     for node in dom.getElementsByTagName('name'):
  28.         server_name = node.firstChild.data
  29.     for node in dom.getElementsByTagName('query_time'):
  30.         server_ping = node.firstChild.data
  31.        
  32.     for node in dom.getElementsByTagName('player'):
  33.         server_players = node.firstChild.data
  34.     for node in dom.getElementsByTagName('maxplayer'):
  35.         server_mplayers = node.firstChild.data
  36.        
  37.     for node in dom.getElementsByTagName('link'):
  38.         server_link = node.firstChild.data
  39.        
  40.     server_info = []
  41.     server_info.append(str(server_ip) + ":" + str(server_port) + " : " + str(server_name) + " : " + str(server_players) + "/" + str(server_mplayers) + " : " + str(server_ping))
  42.    
  43.     return server_info
  44.  
  45. if __name__=="__main__":
  46.     serverinfo = get_server_info()
  47.     for i in serverinfo:
  48.         print i

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post