Skip to content

Instantly share code, notes, and snippets.

@whs
Created April 17, 2011 11:42
Show Gist options
  • Save whs/923969 to your computer and use it in GitHub Desktop.
Save whs/923969 to your computer and use it in GitHub Desktop.
@gladosAtHome source
TWEND
Kit
AAAAA
RUSH
C
TTori
BEAT
TB
AS
Amnesia
SMBoy
DG
KF
#!/usr/bin/python
from __future__ import division
import urllib, re, time
from BeautifulSoup import BeautifulSoup
from decimal import *
getcontext().prec = 4
from oauthtwitter import OAuthApi
from oauth.oauth import OAuthToken
api = OAuthApi("", "", OAuthToken("", ""))
p = urllib.urlopen("http://www.gamingmasters.co.uk/portal/").read()
soup = BeautifulSoup(p)
games=soup.findAll("div", {"class": "GameTooltip"})
# make it to list
def trans(v):
gameName = {
"18500": "DG",
"1250": "KF",
"26500": "C",
"38720": "RUSH",
"38700": "TTori",
"63700": "BEAT",
"15540": "Kit",
"12900": "AS",
"15500": "TWEND",
"40800": "SMBoy",
"57300": "Amnesia",
"15520": "AAAAA",
"35460": "TB"
}
gameId = re.findall("^game_([0-9]+)$", v['id'])[0]
done = Decimal(v.find(id="CurrentProgress").td.string.strip().replace("%", ""))
try:
phr = Decimal(v.find(id="PercentPerHour").td.string.strip().replace("%", ""))
left = v.find(id="HoursAhead").td.string.strip()
except AttributeError:
phr = done = left = "COMPLETE"
done = 100
return [
gameName[gameId],
done, # done
phr, # per hour
left.replace(" days, ", "d").replace("0d", ""), #time left
]
allGames = map(trans, games)
games = filter(lambda x: x[3] != "COMPLETE", allGames)
doneGame = filter(lambda x: x[3] == "COMPLETE", allGames)
doneGame = map(lambda x: x[0], doneGame)
focusList = open("/home/whs/twitterbot/glados-focus").readlines()
while True:
try:
focusName = focusList.pop(0).strip()
except AttributeError:
focus = ["TBD", "", "", ""]
break
try:
focus = filter(lambda x: x[0] == focusName, games)[0]
except IndexError:
continue
else:
break
maxDone = sorted(games, key=lambda x: Decimal(x[1]))
percentStr = soup.find(id="CurrentProgress").td.string.strip()
percent = re.findall(r"^([0-9\.]+)", percentStr)[0]
percentHr = re.findall("([0-9\.]+)% per hour", percentStr)[0]
if maxDone[-1][0] == focus[0]:
topmsg = ""
else:
topmsg = " (%s%% %s%%/hr %s)"%(maxDone[-1][1], maxDone[-1][2], maxDone[-1][3])
message = "%s%% %s%%/hr Top:%s%s Focus:%s (%s%% %s%%/hr %s) #potatofoolsday " % (
percent,percentHr,
#",".join(doneGame),
maxDone[-1][0], topmsg,
focus[0], focus[1], focus[2], focus[3])
def update():
# print message
api.PostUpdate(message)
for i in range(100):
try:
update()
except:
time.sleep(10)
else:
break
#!/usr/bin/python
from __future__ import division
import urllib, re
from decimal import *
getcontext().prec = 4
from oauthtwitter import OAuthApi
from oauth.oauth import OAuthToken
api = OAuthApi("", "", OAuthToken("", ""))
p = urllib.urlopen("http://www.aperturescience.com/glados@home/").read()
progress = re.findall('<div id="overall_progress_bar" style="width: ([0-9]+)px;">', p)[0]
progress = (Decimal(progress) / 494) * 100
#print progress
cpus = re.findall("""<div class="game_progress" style="width: ([0-9]+)px;"></div>
[ ]*<div class="game_cpus">([0-9,]+) CURRENT CPUS</div>
[ ]*<a class="game_row_link" href="http://store.steampowered.com/app/([0-9]+)"></a>""",
p, re.M)
doneGame = re.findall("""<div class="game_cpus">COMPUTATIONS COMPLETE</div>
[ ]*<a class="game_row_link" href="http://store.steampowered.com/app/([0-9]+)"></a>""", p, re.M)
# make it to list
def trans(v):
gameName = {
"18500": "DG",
"1250": "KF",
"26500": "C",
"38720": "Rush",
"38700": "TTori",
"63700": "BEAT",
"15540": "Kit",
"12900": "AS",
"15500": "TWEND",
"40800": "SMBoy",
"57300": "Amnesia",
"15520": "AAAAA",
"35460": "TB"
}
if len(v) == 3:
return [gameName[v[2]], int(v[1].replace(",", "")), (Decimal(v[0])/457)*100]
else:
return gameName[v]
cpus = map(trans, cpus)
doneGame = map(trans, doneGame)
# sort
cpuSort = sorted(cpus, key=lambda x: x[1])
progressSort = sorted(cpus, key=lambda x: x[2])
#print cpus
focus = open("/home/whs/twitterbot/glados-focus").read().strip()
#find focus in list
focusD = filter(lambda x: x[0] == focus, cpus)[0]
def update():
api.PostUpdate("%s%% Top%%: %s (%s%%) TopCPU: %s (%s) Done:%s Focus:%s (%s%% %s CPUs) #potatofoolsday" %
(progress, progressSort[-1][0],
progressSort[-1][2], cpuSort[-1][0],
cpuSort[-1][1], ",".join(doneGame),
focus, focusD[2], focusD[1]))
for i in range(10):
try:
update()
except:
pass
else:
break
#!/usr/bin/python
import urllib, re, time
from simplejson import loads
from decimal import Decimal
from oauthtwitter import OAuthApi
from oauth.oauth import OAuthToken
api = OAuthApi("", "", OAuthToken("", ""))
p = urllib.urlopen("http://hasportal2launchedyet.com/data.json").read()
json = loads(p)
games = json['gamedata']
# make it to list
def trans(v):
gameName = {
"18500": "DG",
"1250": "KF",
"26500": "C",
"38720": "RUSH",
"38700": "TTori",
"63700": "BEAT",
"15540": "Kit",
"12900": "AS",
"15500": "TWEND",
"40800": "SMBoy",
"57300": "Amnesia",
"15520": "AAAAA",
"35460": "TB"
}
return [
gameName[v['id']],
Decimal(v['progress']), # done
v['timeleft'],
v['isfocus'], # True = focus
Decimal(str(v['percentperhour'])),
]
allGames = map(trans, games.itervalues())
games = filter(lambda x: x[1] != 100, allGames)
#doneGame = filter(lambda x: x[1] == 100, allGames)
#doneGame = map(lambda x: x[0], doneGame)
focus = filter(lambda x: x[3], games)[0]
maxDone = sorted(games, key=lambda x: Decimal(x[1]))
maxDone = sorted(games, key=lambda x: Decimal(x[1]))
percent = json['overall']
percentHr = json['percentperhour']
potato = json['potatoes']
if maxDone[-1][0] == focus[0]:
topmsg = ""
else:
topmsg = " (%s%% %s%%/hr %s)"%(maxDone[-1][1], maxDone[-1][4], maxDone[-1][2])
message = "%s%% %s%%/hr %s potatoes Top:%s%s Focus:%s (%s%% %s%%/hr %s) #potatofoolsday" % (
percent, percentHr, potato,
#",".join(doneGame),
maxDone[-1][0], topmsg,
focus[0], focus[1], focus[4], focus[2])
def update():
# print message
api.PostUpdate(message)
update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment