Code:
import requests
def getKey(item):
return item[0]
GAME_ID_BEGIN = 500
GAME_ID_END = 5000
base_url = "http://www.j-archive.com/showgame.php?game_id="
total_games = GAME_ID_END - GAME_ID_BEGIN + 1
error_games = 0
game = GAME_ID_BEGIN
two_thirds_games = 0
min_bets = 0
non_min_bets = 0
while game <= GAME_ID_END:
# [pre-FJ, post-FJ, wager, correct?]
scores = [[0,0,0, False],[0,0,0, False],[0,0,0, False]]
has_error = False
r = requests.get(base_url+str(game))
if r.status_code != 200:
print(game, "was not a valid game id")
continue
lines = r.text.split('\n')
for i in range(len(lines)):
# looking ahead 9-11 or 8-10 lines is based on examing the HTML source code... lame
try:
if "end of the Double" in lines[i]:
scores[0][0] = int(lines[i+9].split("$")[1].split("<")[0].replace(",",""))
scores[1][0] = int(lines[i+10].split("$")[1].split("<")[0].replace(",",""))
scores[2][0] = int(lines[i+11].split("$")[1].split("<")[0].replace(",",""))
if "Final scores:" in lines[i]:
scores[0][1] = int(lines[i+8].split("$")[1].split("<")[0].replace(",",""))
scores[1][1] = int(lines[i+9].split("$")[1].split("<")[0].replace(",",""))
scores[2][1] = int(lines[i+10].split("$")[1].split("<")[0].replace(",",""))
except:
print ("Error occurred on game", game)
error_games += 1
has_error = True
break
if has_error == True:
game += 1
continue
# determine wager amount and if it was correct
for i in range(3):
scores[i][2] = abs(scores[i][1] - scores[i][0])
scores[i][3] = scores[i][1] >= scores[i][0]
scores.sort(key = getKey, reverse=True)
# establish 2/3 game situation
if scores[1][0] >= scores[0][0] * .667:
two_thirds_games += 1
# Determine a min-bet by comparing to a range of [0, 3B - 2A]
if scores[1][2] < 3*scores[1][0] - 2*scores[0][0]:
#print (scores)
#print ("Min-bet of", scores[1][2], "on a pre-FJ score of", scores[1][0])
min_bets += 1
else: non_min_bets += 1
game += 1
print ("Total # of games:", total_games)
print ("Total # of game w/o errors:", total_games - error_games)
print ("Total # of 2/3 games:", two_thirds_games)
print ("Out of the", two_thirds_games, "total 2/3 games,", min_bets, "were min-bet and", non_min_bets, "were not.")