Created
April 17, 2011 23:08
-
-
Save AmandaCameron/924578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
import urllib2 | |
import re | |
import locale | |
locale.setlocale(locale.LC_ALL, "") | |
origRegEx = re.compile(r"g_originalEstimate = (\d+) \+"); | |
updatedRegEx = re.compile(r"g_updatedEstimate = (\d+) \+"); | |
potatoRegEx = re.compile(r"g_currentPotatoCount = (\d+);"); | |
changeRegEx = re.compile(r"g_currentPotatoConsumptionRate = (\d+\.\d+)") | |
gameRegEx = re.compile(r"class=\"game_progress(\" style=\"width: (\d+)px;\"| game_progress_complete\")"); | |
cpuRegEx = re.compile(r"<div class=\"game_cpus\">(([0-9,]+) CURRENT CPUS|COMPUTATIONS COMPLETE)</div>") | |
overallRegEx = re.compile(r"<div id=\"overall_progress_bar\" style=\"width: (\d+)px;\">") | |
def prettyNumber(num): | |
return locale.format("%d", int(num), 1) | |
def prettyTime(secs): | |
if not isinstance(secs, int): | |
secs = int(secs) | |
mins = secs // 60 | |
hours = mins // 60 # There are actualy some hour+ long youtube videos | |
secs = secs % 60 | |
mins = mins % 60 | |
time = "%02d:%02d" % (mins, secs) | |
if hours > 0: | |
time = "%d:%s" % (hours, time) | |
return time | |
def look_cmd(): | |
body = urllib2.urlopen("http://www.aperturescience.com/glados@home/") | |
body = body.read() | |
g = origRegEx.search(body) | |
original = int(g.group(1)) | |
g = updatedRegEx.search(body) | |
updated = int(g.group(1)) | |
print "Original: " + prettyTime(original) | |
print "Updated: " + prettyTime(updated) | |
print "Difference: " + prettyTime(original - updated); | |
g = potatoRegEx.search(body) | |
potatos = int(g.group(1)) | |
g = changeRegEx.search(body) | |
change = float(g.group(1)) | |
potatoBoost = potatos / change; | |
print u"Boost: %s -- %s @ %.2f / sec" % (prettyTime(potatoBoost), | |
prettyNumber(potatos), change); | |
games = [ | |
"Defence Grid ", | |
"Killing Floor ", | |
"Cobs ", | |
"Rush ", | |
"Toki Tori ", | |
"Bit. Trip. Beat. ", | |
"1...2...3... Kick it ", | |
"AudioSurf ", | |
"WEOTW ", | |
"Super Meat Boy ", | |
"Amnesia ", | |
"AAAAAAHH! ", | |
"The Ball " | |
] | |
percentages = [0] * 13 | |
cpus = [-1] * 13 | |
for i,m in enumerate(gameRegEx.finditer(body)): | |
if m.group(2) is not None: | |
s = int(m.group(2)) / 457.0 | |
s *= 100 | |
s = "%d%%" % s | |
else: | |
s = "100%" | |
percentages[i] = s | |
#print games[i], s | |
for i,m in enumerate(cpuRegEx.finditer(body)): | |
if m.group(2) is not None: | |
s = m.group(2) | |
else: | |
s = -1 | |
cpus[i] = s | |
for i,g in enumerate(games): | |
cpu = cpus[i] | |
complete = percentages[i] | |
if cpu == -1: | |
cpu = "N/A" | |
c = "\x1b[46m" | |
else: | |
c = "\x1b[41m" | |
print "%s%25s | %6s | %4s\x1b[0;0m" % (c, g, cpu, complete) | |
g = overallRegEx.search(body) | |
overall = int(g.group(1)) / 494.0 | |
overall *= 100 | |
overall = "%d%%" % overall | |
print "%25s | %6s | %4s" % ("Overall Progress ", "N/A", overall) | |
look_cmd() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment