Skip to content

Instantly share code, notes, and snippets.

@dsosby
Created August 22, 2011 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dsosby/1163805 to your computer and use it in GitHub Desktop.
Save dsosby/1163805 to your computer and use it in GitHub Desktop.
Choose best odds at public drawn hunt for Texas hunts @ https://www2.tpwd.state.tx.us/huntwild/hunt/public/lands/public_hunting_system/search/
import sys
import re
import string
import urllib
filename = "".join(sys.argv[1:])
if filename.startswith("http"):
htmlFile = urllib.urlopen(filename)
else:
htmlFile = open(filename, 'r')
locationRE = re.compile(r"<h3 class=\"clear nobottommargin\"><a href=.*>(.*)</a>")
chancesDrawnRE = re.compile(r".*?([\d,]+) applicants for (\d+) permit.*")
successChanceRE = re.compile(r".*Hunter Success: (\d+)%")
curLocation = ""
chancesDrawn = 0
successChance = 0
results = []
for line in htmlFile:
match = locationRE.match(line)
if match is not None:
curLocation = match.group(1)
chancesDrawn = 0
successChance = 0
continue
match = chancesDrawnRE.match(line)
if match is not None:
applicants = match.group(1).replace(',','')
drawn = match.group(2)
if int(applicants) == 0:
chancesDrawn = 0.0
else:
chancesDrawn = float(drawn) / float(applicants)
if chancesDrawn > 1:
print "DEBUG %s %s %s" % (curLocation, applicants, drawn)
continue
match = successChanceRE.match(line)
if match is not None:
successChance = int(match.group(1))
#This is the last piece of data, so process everything and store
chanceIllBeSuccessful = chancesDrawn * (successChance / 100.0)
#print "DEBUG location=%s apps=%f chancesDrawn = %f successChance = %d" % (curLocation, float(applicants), chancesDrawn, successChance)
results.append( (curLocation, chanceIllBeSuccessful) )
sortedResults = sorted(results, key=lambda location: location[1], reverse=True)
for result in sortedResults:
print string.ljust(result[0], 30), "%3.1f%%" % (result[1]*100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment