Last active
June 25, 2022 05:24
-
-
Save ErisianArchitect/50c51e3d0a6030406217 to your computer and use it in GitHub Desktop.
Checks your lotto numbers against all lotto numbers for powerball.
This file contains hidden or 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
This utility requires Python3 and the requests module (pip install requests) | |
Put lotto.py, numbers.txt, and config.ini in a folder together. | |
edit numbers.txt with your lotto numbers in the format provided. | |
format: (where PB is your powerball number) | |
mm/dd/yyyy 00 00 00 00 00 PB | |
if your date is '00/00/0000', then it will check all powerball numbers, otherwise it only checks the date for that number. |
This file contains hidden or 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
[SETTINGS] | |
readmethod = LINE | |
filename = numbers.txt |
This file contains hidden or 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/env python3 | |
#lotto.py | |
#Author: D* F* | |
#Github: https://github.com/SevenSolaris | |
import requests, collections, json, os, configparser | |
pb_url = r'http://www.powerball.com/powerball/winnums-text.txt' | |
#Replace this array with your winning numbers | |
#the last number must always be the powerball number or None. | |
cfg = configparser.ConfigParser() | |
if os.path.isfile('config.ini'): | |
with open('config.ini','r') as f: | |
cfg.read_file(f) | |
else: | |
#config.ini does not exist, so we're going to make it exist. | |
#--config.ini | |
''' | |
[SETTINGS] | |
readmethod = LINE | |
filename = numbers.txt | |
''' | |
cfg.read_dict({'SETTINGS':{'readmethod':'LINE','filename':'numbers.txt'}}) | |
with open('config.ini','w') as f: | |
cfg.write(f) | |
config = dict( | |
readmethod = cfg['SETTINGS']['readmethod'],#LINE (Reads the lines, splits the text), JSON (reads JSON) | |
filename = cfg['SETTINGS']['filename']#Default value is numbers.txt | |
) | |
#LINE file format example: | |
LINE_EXAMPLE = '''\ | |
#You can use comments. | |
#(The date is required) | |
#mm/dd/yyyy 00 00 00 00 00 PB | |
01/09/2016 16 19 32 34 57 13 | |
''' | |
#JSON file format example: | |
JSON_EXAMPLE = '''\ | |
[ | |
["01/09/2016","16","19","32","34","57","13"] | |
] | |
''' | |
#Checks if 'i' is iterable. | |
def isiter(i): | |
return isinstance(i,collections.Iterable) | |
class Lotto: | |
__slots__ = ('date','balls','PP') | |
def __init__(self,date,balls): | |
self.date = date | |
self.balls = balls if len(balls) < 7 else balls[:6] | |
if len(balls) == 7: | |
self.PP = balls[-1] | |
else: | |
self.PP = None | |
@property | |
def powerball(self): | |
return self.balls[-1 if len(self.balls) < 7 else -2] | |
def check(self,lot): | |
'''return (int(winner_level),bool(powerball))''' | |
ivals = None | |
if type(lot) is Lotto: | |
ivals = lot.balls | |
elif type(lot) is str: | |
ivals = lot.split() | |
elif isiter(lot): | |
ivals = [v for v in lot] | |
match_sum = sum(1 for i in range(5) if self.balls[i] in ivals) | |
power_ball = self.powerball == ivals[-1 if len(ivals) < 7 else -2] | |
return (match_sum, power_ball) if (match_sum or power_ball) else None | |
def __str__(self): | |
return '%s %s' % (self.date or '00/00/0000', ' '.join(self.balls)) | |
def __repr__(self): | |
return 'Lotto(date=%r, balls=%r)' % (self.date, self.balls) | |
readmeth = config.get('readmethod','LINE') | |
fname = config.get('filename','numbers.txt') | |
my_nums = [] | |
#The LINE method is the preferred method because it requires less typing | |
#to input all of your numbers. | |
if readmeth == 'LINE': | |
if os.path.isfile(fname): | |
with open(fname,'r') as f: | |
src = f.read() | |
# [1:] because the first line is useless data | |
lines = src.splitlines()[1:] | |
for line in lines: | |
csv = line.split() | |
if csv[0][0] == '#': | |
continue | |
my_nums.append(Lotto(csv[0],csv[1:])) | |
else: | |
raise FileNotFoundError('%r was not found' % fname) | |
elif readmeth == 'JSON': | |
if os.path.isfile(fname): | |
with open(fname,'r') as f: | |
d = json.load(f) | |
for lot in d: | |
my_nums.append(Lotto(lot[0],lot[1:])) | |
else: | |
raise FileNotFoundError('%r was not found' % fname) | |
resp = requests.get(pb_url) | |
src = resp.text | |
lines = src.splitlines()[1:] | |
#Now that we have our response text, and have split it into lines, | |
#we can iterate through the lines to find the line that has our desired date. | |
my_wins = [] | |
for line in lines: | |
args = line.split() | |
l_date = args[0] | |
l_nums = args[1:] | |
for lot in my_nums: | |
if lot.date == '00/00/0000' or lot.date == l_date: | |
chk = lot.check(l_nums) | |
if chk: | |
my_wins.append((l_date,) + chk + (lot,)) | |
print('Win!', *my_wins[-1]) | |
#beyond this point you can do something with my_wins | |
#format of objects in my_wins is: | |
#(str(date<mm/dd/yyyy>), int(win_level), bool(power_ball), Lotto(your_winning_number)) |
This file contains hidden or 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
mm/dd/yyyy 00 00 00 00 00 PB | |
mm/dd/yyyy 00 00 00 00 00 PB | |
mm/dd/yyyy 00 00 00 00 00 PB | |
mm/dd/yyyy 00 00 00 00 00 PB | |
mm/dd/yyyy 00 00 00 00 00 PB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment