Last active
June 7, 2018 18:09
-
-
Save jhavard/1eed7915b2db4a61230b797748755b25 to your computer and use it in GitHub Desktop.
Matches list of powerball numbers against the powerball.com published numbers
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
#!/usr/bin/python | |
# note that this will no longer work since they changed the API location | |
# and I really don't care enough about this to update the script. Sorry! | |
import httplib | |
import json | |
conn = httplib.HTTPSConnection('www.powerball.com') | |
conn.request('GET', '/api/v1/numbers/powerball/recent') | |
resp = conn.getresponse() | |
try: | |
rdr = resp.read() | |
except: | |
None | |
conn = httplib.HTTPSConnection('www.powerball.com') | |
conn.request('GET', '/api/v1/estimates/powerball') | |
resp = conn.getresponse() | |
try: | |
estrep = resp.read() | |
est = json.loads(estrep) | |
except: | |
None | |
draw = json.loads(rdr) | |
# {u'field_draw_date': u'2018-03-17', u'field_multiplier': u'2', u'field_winning_numbers': u'22,57,59,60,66,07'} | |
foo = draw[0]['field_winning_numbers'].encode('ascii').split(',') | |
dwb = foo[0:5] | |
dpb = foo[5] | |
wins = { 'JACKPOT' : 0, 'MATCH5': 0, 'MATCH4PB' : 0, 'MATCH4' : 0, 'MATCH3' : 0, 'MATCHPB' : 0 , 'LOSS' : 0 } | |
with open('billion_powerball_numbers_fixed.txt', 'r') as fp: | |
#with open('test.txt', 'r') as fp: | |
for line in fp: | |
aaa = line.strip().split(',') | |
pwb = aaa[0:5] | |
ppb = aaa[5] | |
ct = len([x for x in pwb if x in dwb]) | |
pb = (ppb == dpb) | |
if ( ct == 5 ) and ( pb ): | |
wins['JACKPOT'] += 1 | |
elif ( ct == 5 ): | |
wins['MATCH5'] += 1 | |
elif ( ct == 4 ) and ( pb ): | |
wins['MATCH4PB'] += 1 | |
elif ( ct == 4 ): | |
wins['MATCH4'] += 1 | |
elif ( ct == 3 ) and ( pb ): | |
wins['MATCH4'] += 1 | |
elif ( ct == 3 ): | |
wins['MATCH3'] += 1 | |
elif ( ct == 2 ) and ( pb ): | |
wins['MATCH3'] += 1 | |
elif ( pb ): | |
wins['MATCHPB'] += 1 | |
else: | |
wins['LOSS'] += 1 | |
print "JACKPOT SPLITS %10d %s %s" % ( wins['JACKPOT'], est[0]['field_prize_amount'], est[0]['field_prize_amount_cash'] ) | |
print "MATCH 5 %10d $%d" % ( wins['MATCH5'], wins['MATCH5'] * 1000000) | |
print "MATCH 4+PB %10d $%d" % ( wins['MATCH4PB'], wins['MATCH4PB'] * 50000) | |
print "MATCH 4 %10d $%d" % ( wins['MATCH4'], wins['MATCH4'] * 100) | |
print "MATCH 3 %10d $%d" % ( wins['MATCH3'], wins['MATCH3'] * 7) | |
print "MATCH PB %10d $%d" % ( wins['MATCHPB'], wins['MATCHPB'] * 4) | |
total = wins['MATCH5'] * 1000000 + wins['MATCH4PB'] * 50000 + wins['MATCH4'] * 100 + wins['MATCH3'] * 7 + wins['MATCHPB'] * 4 | |
print "TOTAL WIN %d TOTAL EXPENSE 2000000000 PROFIT %d" % ( total, total - 2000000000 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment