Mercurial > ~darius > hgwebdir.cgi > scrape-gm
diff scrape-gm.py @ 12:ae9e833e4447
Get game type.
Print game type at the beginning & sort output.
author | darius@inchoate.localdomain |
---|---|
date | Sat, 26 Jul 2008 20:47:08 +0930 |
parents | 22a51e8c0a69 |
children | e8550290e512 |
line wrap: on
line diff
--- a/scrape-gm.py Fri Feb 29 21:05:14 2008 +1030 +++ b/scrape-gm.py Sat Jul 26 20:47:08 2008 +0930 @@ -38,7 +38,8 @@ alltags = re.compile('<[^>]*>') vwhttags = re.compile('<(br|hr)>') hwhttags = re.compile('\ ') - + typetag = re.compile('<td><a href="/GameSearch/([^/]+)/.*</td>') + def __init__(self, description = "", ip = "", port = 0, mapname = "", updateage = 0, numplayers = 0, maxplayers = 0, players = []): self.description = description @@ -57,12 +58,14 @@ # scols[2] = Server IP # scols[3] = Server port # scols[4] = Map name + # scols[5] = Game type # scols[10] = Update age self.tuplere = re.compile("\[?([0-9]+)/([0-9]+)\]?") self.description = pcols[3] self.ip = scols[2] self.port = int(scols[3]) self.mapname = scols[4] + self.gametype = scols[5] self.updateage = scols[10] m = self.tuplere.match(scols[0]) if (m == None): @@ -77,8 +80,8 @@ for p in self.players: plist = plist + " " + str(p) - return "%s (%s:%d) | Map: %s | Players: %d/%d : %s (%s old)" % \ - (self.description, self.ip, self.port, self.mapname, + return "%s: %s (%s:%d) | Map: %s | Players: %d/%d : %s (%s old)" % \ + (self.gametype, self.description, self.ip, self.port, self.mapname, self.numplayers, self.maxplayers, plist, self.updateage) @@ -87,6 +90,10 @@ GetTuple = staticmethod(GetTuple) def FixTags(s): + # Mangle game type + t = Server.typetag.match(s) + if t != None: + s = t.group(1) s = re.sub(Server.vwhttags, '\n', s) s = re.sub(Server.hwhttags, '', s) s = str(BeautifulSoup.BeautifulStoneSoup( \ @@ -103,7 +110,7 @@ #print "Unable to find results" return None - servertbl = playertbl.findNext("table", "results") + servertbl = playertbl.findNext("table") playerrows = playertbl.findAll("tr") serverrows = servertbl.findAll("tr") @@ -158,10 +165,14 @@ elif (len(servers) == 0): print "No players found" else: + tmp = [] + for i in servers: + tmp.append(servers[i]) + tmp.sort() i = 0 - for s in servers: + for s in tmp: i = i + 1 - print servers[s] + print s if (i >= maxhits): print "*** Stopping after " + str(maxhits) + " hits" break