User:Cynique/gottgen
From Guild Wars Wiki
Jump to navigationJump to search
This is my script for generating the totals section for the Gift of the Traveler/Drop rate page:
import time infile = open("sampledata.txt","r") totals = {} valid_tokens = ( "aged ale", "ale keg", "ale", "poppers", "rockets", "sparklers", "fireworks", "disco balls", "honey jar", "honeycombs", "green rock", "blue rock", "red rock", "mysterious stone", "mercantile stone", "mysterious tonic", "cottontail tonic", "walking stick", "yakkington", "vds", "vampiric dragon sword", "gwen", "gwen doll", "moss spider", "moss", "ids", "icy dragon sword", "razor", "ascalon razor", "bo staff", "brown rabbit", "rabbit", "everlasting fireworks", "everlasting cottontail" ) for token in valid_tokens: totals[token] = 0 grand_total = 0 for line in infile.readlines(): line = line.replace( '\n', '' ) line = line.replace( '{', '' ) line = line.replace( '}', '' ) items = line.split( "|" ) if items[0] == "": continue items = items[1:] for item in items: if item.find( "=" ) == -1: continue if item.find( "[" ) != -1 or item.find( "]" ) != -1: continue parts = item.split( "=" ) if len(parts) != 2: continue name, value = parts name = name.strip() value = value.strip() if not name in valid_tokens: continue count = 0 for digit in value: if not digit.isdigit(): continue count += 1 if count == 0: continue value = int( value[0:count] ) totals[name] += value grand_total += value print "<!-- Totals start here... -->" print "|-" totals_string = "| %d |"%(grand_total) totals_string += "| %d |"%(totals["ale"]) totals_string += "| %d |"%(totals["aged ale"]) totals_string += "| %d |"%(totals["ale keg"]) totals_string += "| %d |"%(totals["poppers"]) totals_string += "| %d |"%(totals["rockets"]) totals_string += "| %d |"%(totals["sparklers"]) totals_string += "| %d |"%(totals["fireworks"]) totals_string += "| %d |"%(totals["disco balls"]) totals_string += "| %d |"%(totals["honey jar"]) totals_string += "| %d |"%(totals["honeycombs"]) totals_string += "| %d |"%(totals["green rock"]) totals_string += "| %d |"%(totals["blue rock"]) totals_string += "| %d |"%(totals["red rock"]) totals_string += "| %d |"%(totals["mysterious stone"]) totals_string += "| %d |"%(totals["mercantile stone"]) totals_string += "| %d |"%(totals["mysterious tonic"]) totals_string += "| %d |"%(totals["cottontail tonic"]) totals_string += "| %d |"%(totals["everlasting cottontail"]) totals_string += "| %d |"%(totals["gwen"] + totals["gwen doll"]) totals_string += "| %d |"%(totals["yakkington"]) totals_string += "| %d |"%(totals["brown rabbit"] + totals["rabbit"]) totals_string += "| %d |"%(totals["vampiric dragon sword"] + totals["vds"]) totals_string += "| %d |"%(totals["bo staff"]) totals_string += "| %d |"%(totals["walking stick"]) totals_string += "| %d |"%(totals["icy dragon sword"] + totals["ids"]) totals_string += "| %d |"%(totals["razor"] + totals["ascalon razor"]) totals_string += "| %d |"%(totals["moss spider"] + totals["moss"]) totals_string += "| %d |"%(totals["everlasting fireworks"]) print totals_string+"| ~~~" print "|-" totals_string = "| 100% |" totals_string += "| %.3f%% |"%(float(totals["ale"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["aged ale"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["ale keg"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["poppers"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["rockets"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["sparklers"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["fireworks"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["disco balls"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["honey jar"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["honeycombs"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["green rock"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["blue rock"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["red rock"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["mysterious stone"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["mercantile stone"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["mysterious tonic"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["cottontail tonic"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["everlasting cottontail"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["gwen"] + totals["gwen doll"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["yakkington"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["brown rabbit"] + totals["rabbit"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["vampiric dragon sword"] + totals["vds"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["bo staff"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["walking stick"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["icy dragon sword"] + totals["ids"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["razor"] + totals["ascalon razor"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["moss spider"] + totals["moss"])*100/grand_total) totals_string += "| %.3f%% |"%(float(totals["everlasting fireworks"])*100/grand_total) print totals_string + "| ~~~~~" timestamp = time.strftime( "%Y-%m-%d %H:%m:%S" ) print "<!-- END of Totals. Autogenerated at %s by Cynique's GotT Totals Generator. Copyright 2011 Cynique. -->" % timestamp