initial commit

This commit is contained in:
Quality Coder 2022-01-05 19:59:44 -06:00
parent 423f5de9a3
commit 415aad8bff
16 changed files with 275 additions and 26 deletions

View file

@ -1,29 +1,27 @@
# README #
# Generic Lottery game number checker #
Currently includes Powerball and Megamillions.
This README would normally document whatever steps are necessary to get your application up and running.
You add your picks to {game}/picks.py, and run `./play -g {gamename}` eg `.play.py -g powerball`
### What is this repository for? ###
The script will pull the current winning numbers from an rss feed, and compare them to each ticket you list in the picks.py file for that game.
* Quick summary
* Version
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
### How do I get set up? ###
* Summary of set up
* Configuration
* Dependencies
* Database configuration
* How to run tests
* Deployment instructions
### Contribution guidelines ###
* Writing tests
* Code review
* Other guidelines
### Who do I talk to? ###
* Repo owner or admin
* Other community or team contact
The output per ticket:
```text
Winning Numbers: [2, 13, 32, 33, 48]
Winning Powerball: 22
Your Numbers: (1, 2, 3, 4, 5)
Your Powerball: 9
Matched Numbers: [2]
Matched Powerball: False
Not a Winner!
```
OR
```text
Winning Numbers: [2, 13, 32, 33, 48]
Winning Powerball: 22
Your Numbers: (1, 2, 3, 4, 5)
Your Powerball: 22
Matched Numbers: [2]
Matched Powerball: True
Ticket is worth: 8
```

36
lib/Feed.py Normal file
View file

@ -0,0 +1,36 @@
import feedparser
class Feed:
def __init__(self, feed):
self.feed = 'https://www.texaslottery.com/export/sites/lottery/rss/tlc_latest.xml'
self.parsed_feed = feedparser.parse(self.feed)
self.game_entries = feed
self.modifiers = {
'Billion': 1000000000,
'Million': 1000000
}
def get_winning_numbers(self):
entry = self.game_entries
nums_pre = self.parsed_feed.entries[entry['winning_numbers']].summary
nums_pre = nums_pre.replace(entry['special_ball'], '-').replace(f' {entry["multiplier"]}', '-')
nums = nums_pre.split(' - ')
winning_numbers = nums[:5]
for idx, num in enumerate(nums[:5]):
winning_numbers[idx] = int(num)
special_ball = int(nums[5])
multiplier = int(nums[6])
return {'numbers': winning_numbers, 'special_ball': special_ball, 'multiplier': multiplier}
def get_jackpot(self):
entry = self.game_entries
jp_pre = self.parsed_feed.entries[entry['jackpot']].summary
jp_pre = jp_pre[jp_pre.index('Cash'):]
jp_pre = jp_pre[jp_pre.index(':') + 3:]
jp_data = jp_pre.split()
return float(jp_data[0]) * self.modifiers[jp_data[1]]

70
lib/Ticket.py Normal file
View file

@ -0,0 +1,70 @@
class Ticket:
def __init__(self, my_picks, my_special_ball):
self.jackpot = 0
self.my_picks = my_picks
self.my_special_ball = my_special_ball
self.winning_numbers = []
self.special_ball = None
self.multiplier = None
self.matched_numbers = []
self.matched_special_ball = None
self.winnings = 0
self.feed = None
def get_jp_amount(self):
self.jackpot = self.feed.get_jackpot()
def get_winning_numbers(self):
winners = self.feed.get_winning_numbers()
self.winning_numbers = winners['numbers']
self.special_ball = winners['special_ball']
self.multiplier = winners['multiplier']
def process_ticket(self):
self.check_numbers()
self.check_special_ball()
self.get_jp_amount()
special_ball_wins = self.get_winnings_with_special_ball(self.jackpot)
non_special_ball_wins = self.get_winnings_without_special_ball()
self.process_winnings(special_ball_wins, non_special_ball_wins)
def check_numbers(self):
for num in self.my_picks:
if num in self.winning_numbers:
self.matched_numbers.append(num)
def check_special_ball(self):
self.matched_special_ball = False
if self.special_ball is not None and self.my_special_ball == self.special_ball:
self.matched_special_ball = True
def process_winnings(self, special_ball_wins, non_special_ball_wins):
wins = non_special_ball_wins
if self.matched_special_ball:
wins = special_ball_wins
self.winnings = wins[self.multiplier][len(self.matched_numbers)]
self.output_ticket()
def output_ticket(self):
special_ball = self.feed.game_entries["special_ball"]
print(f'Winning Numbers: {self.winning_numbers}')
print(f'Winning {special_ball}: {self.special_ball}')
print(f'Your Numbers: {self.my_picks}')
print(f'Your {special_ball}: {self.my_special_ball}')
print(f'Matched Numbers: {self.matched_numbers}')
print(f'Matched {special_ball}: {"True" if self.matched_special_ball else "False"}')
if self.winnings > 0:
print(f'Ticket is worth: {self.winnings}')
else:
print(f'Not a Winner!')
print()
def get_winnings_with_special_ball(self, jp):
pass
def get_winnings_without_special_ball(self):
pass

View file

@ -0,0 +1,18 @@
from lib.Ticket import Ticket
from lib.Feed import Feed
from .feed import feed
from .winning_structure import get_winnings_mb, get_winnings_no_mb
class MegaMillions(Ticket):
def __init__(self, my_picks, my_special_ball):
super().__init__(my_picks, my_special_ball)
self.feed = Feed(feed)
self.get_winning_numbers()
def get_winnings_with_special_ball(self, jp):
return get_winnings_mb(self.jackpot)
def get_winnings_without_special_ball(self):
return get_winnings_no_mb()

0
megamillions/__init__.py Normal file
View file

6
megamillions/feed.py Normal file
View file

@ -0,0 +1,6 @@
feed = {
'winning_numbers': 2,
'jackpot': 3,
'special_ball': 'MegaBall',
'multiplier': 'Megaplier'
}

13
megamillions/game.py Executable file
View file

@ -0,0 +1,13 @@
#! /usr/bin/python3
from .picks import my_picks
from .MegaMillions import MegaMillions
cur_picks = []
cur_pb = 0
for idx, tkt in enumerate(my_picks):
cur_picks = tkt['picks']
cur_pb = tkt['mb']
pbtkt = MegaMillions(cur_picks, cur_pb)
pbtkt.process_ticket()

4
megamillions/picks.py Normal file
View file

@ -0,0 +1,4 @@
my_picks = [
{'picks': (1, 2, 3, 4, 5), 'mb': 9},
{'picks': (2, 3, 4, 5, 6), 'mb': 19},
]

View file

@ -0,0 +1,16 @@
def get_winnings_mb(jackpot_cash):
return {
2: [4, 8, 20, 400, 20_000, jackpot_cash],
3: [6, 12, 30, 600, 30_000, jackpot_cash],
4: [8, 16, 40, 800, 40_000, jackpot_cash],
5: [10, 20, 50, 1_000, 50_000, jackpot_cash]
}
def get_winnings_no_mb():
return {
2: [0, 0, 0, 20, 1_000, 2_000_000],
3: [0, 0, 0, 30, 1_500, 3_000_000],
4: [0, 0, 0, 40, 2_000, 4_000_000],
5: [0, 0, 0, 50, 2_500, 5_000_000]
}

27
play.py Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/python3
import getopt
import sys
import importlib
def main(argv):
game = ''
usage = 'play.py -g <gamename>'
try:
opts, args = getopt.getopt(argv, "hg:", ["game="])
except getopt.GetoptError:
print(usage)
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(usage)
sys.exit()
elif opt in ("-g", "--game"):
game = arg
importlib.import_module(f'{game}.game')
if __name__ == "__main__":
main(sys.argv[1:])

18
powerball/Powerball.py Normal file
View file

@ -0,0 +1,18 @@
from lib.Ticket import Ticket
from lib.Feed import Feed
from .feed import feed
from .winning_structure import get_winnings_pb, get_winnings_no_pb
class Powerball(Ticket):
def __init__(self, my_picks, my_special_ball):
super().__init__(my_picks, my_special_ball)
self.feed = Feed(feed)
self.get_winning_numbers()
def get_winnings_with_special_ball(self, jp):
return get_winnings_pb(self.jackpot)
def get_winnings_without_special_ball(self):
return get_winnings_no_pb()

0
powerball/__init__.py Normal file
View file

6
powerball/feed.py Normal file
View file

@ -0,0 +1,6 @@
feed = {
'winning_numbers': 0,
'jackpot': 1,
'special_ball': 'Powerball',
'multiplier': 'Power Play'
}

13
powerball/game.py Executable file
View file

@ -0,0 +1,13 @@
#! /usr/bin/python3
from .picks import my_picks
from .Powerball import Powerball
cur_picks = []
cur_pb = 0
for idx, tkt in enumerate(my_picks):
cur_picks = tkt['picks']
cur_pb = tkt['pb']
pbtkt = Powerball(cur_picks, cur_pb)
pbtkt.process_ticket()

4
powerball/picks.py Normal file
View file

@ -0,0 +1,4 @@
my_picks = [
{'picks': (1, 2, 3, 4, 5), 'pb': 22},
{'picks': (2, 3, 4, 5, 6), 'pb': 19},
]

View file

@ -0,0 +1,20 @@
def get_winnings_pb(jackpot_cash):
return {
0: [4, 4, 7, 100, 50_000, jackpot_cash],
2: [8, 8, 14, 200, 100_000, jackpot_cash],
3: [12, 12, 21, 300, 150_000, jackpot_cash],
4: [16, 16, 28, 400, 200_000, jackpot_cash],
5: [20, 20, 35, 500, 250_000, jackpot_cash],
10: [40, 40, 70, 1_000, 500_000, jackpot_cash]
}
def get_winnings_no_pb():
return {
0: [0, 0, 0, 7, 100, 1_000_000],
2: [0, 0, 0, 14, 200, 2_000_000],
3: [0, 0, 0, 21, 300, 2_000_000],
4: [0, 0, 0, 28, 400, 2_000_000],
5: [0, 0, 0, 35, 500, 2_000_000],
10: [0, 0, 0, 70, 1_000, 2_000_000]
}