From db567181c7b9e3701879443c38423c3b230804d4 Mon Sep 17 00:00:00 2001 From: williedynamite Date: Sun, 27 Sep 2026 14:25:33 -0400 Subject: [PATCH] Added cash pop and fixed some bugs preventing numbers from updating --- .gitignore | 0 README.md | 0 c25_ans.csv | 2 +- cash25.py | 33 ++++++++++---- cashpop.py | 58 +++++++++++++++++++++++++ cp_ans.csv | 2 + cron.txt | 18 +++++--- d3_ans.csv | 2 +- d4_ans.csv | 2 +- daily3.py | 33 +++++++++----- daily4.py | 31 +++++++++---- dump.rdb | Bin excel_lotto_records/cash25.xlsx | Bin excel_lotto_records/daily3.xlsx | Bin excel_lotto_records/daily4.xlsx | Bin excel_lotto_records/lotto.xlsx | Bin excel_lotto_records/lotto_america.xlsx | Bin excel_lotto_records/lotto_megamil.xlsx | Bin la_ans.csv | 2 +- lotto_america.py | 38 +++++++++++----- lottopy_pb.py | 39 ++++++++++++----- megamil.py | 37 +++++++++++----- mm_ans.csv | 2 +- pb_ans.csv | 2 +- requirements.txt | 0 start.sh | 2 +- 26 files changed, 231 insertions(+), 72 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 README.md mode change 100644 => 100755 c25_ans.csv create mode 100755 cashpop.py create mode 100644 cp_ans.csv mode change 100644 => 100755 cron.txt mode change 100644 => 100755 d3_ans.csv mode change 100644 => 100755 d4_ans.csv mode change 100644 => 100755 dump.rdb mode change 100644 => 100755 excel_lotto_records/cash25.xlsx mode change 100644 => 100755 excel_lotto_records/daily3.xlsx mode change 100644 => 100755 excel_lotto_records/daily4.xlsx mode change 100644 => 100755 excel_lotto_records/lotto.xlsx mode change 100644 => 100755 excel_lotto_records/lotto_america.xlsx mode change 100644 => 100755 excel_lotto_records/lotto_megamil.xlsx mode change 100644 => 100755 la_ans.csv mode change 100644 => 100755 mm_ans.csv mode change 100644 => 100755 pb_ans.csv mode change 100644 => 100755 requirements.txt diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/c25_ans.csv b/c25_ans.csv old mode 100644 new mode 100755 index 02519a6..cbe7608 --- a/c25_ans.csv +++ b/c25_ans.csv @@ -1,2 +1,2 @@ Forecast,Chance -9 - 12 - 13 - 19 - 20 - 22,12/6325 +1 - 4 - 16 - 18 - 19 - 20,1/177100 diff --git a/cash25.py b/cash25.py index 0fad753..d0ccd88 100755 --- a/cash25.py +++ b/cash25.py @@ -1,23 +1,33 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac +from math import comb import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games df_old = pd.read_excel('./excel_lotto_records/cash25.xlsx') salvaged = df_old[['Date', 'Numbers']] - url = 'https://wvlottery.com/draw-games/cash-25/?game-analyze=cash-25&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=10&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", - "X-Requested-With": "XMLHttpRequest" } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) @@ -29,11 +39,15 @@ def get_data(): date, nums = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only count numbers that can still be called, the ball ranges have changed over the years +# so the old records have some numbers that dont exist in the game anymore +sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 25] for n in range(0, 25): most_common= Counter(sep).most_common(6) @@ -41,8 +55,9 @@ for n in range(0, 25): frequency = [v[-1] for v in most_common] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency) -Chance = frac(total_freq, 177100) # Chance = number call freq / all possible numbers i.e. 177100 +# Chance = 1 / every possible ticket, 25 choose 6 = 177100 +# every ticket has the same odds, the forecast just goes with the numbers that get called the most +Chance = frac(1, comb(25, 6)) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} \n" diff --git a/cashpop.py b/cashpop.py new file mode 100755 index 0000000..11bf633 --- /dev/null +++ b/cashpop.py @@ -0,0 +1,58 @@ +# WVLottopy: Matteo DiBiagio +from fractions import Fraction as frac +import pandas as pd +import requests +from collections import Counter +import csv + +def get_data(): + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=24&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' + header = { + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", + } + # Get web data, cash pop draws every 15 min so only use the last ~3000 draws (about a month) + web = {'Date': [], 'Numbers': []} + page = 0 + while page < 6: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + if data['last']: + break + page += 1 + df2 = pd.DataFrame(web) + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + return date, nums + +date, nums = get_data() + +# Formatting +hyphenfree = [] +for x in nums: + hyphenfree.append(x.replace('–',', ')) +splitlist = ", ".join(hyphenfree) +sep = splitlist.split(", ") +# Only keep 1 - 15, just in case anything weird comes back from the site +sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 15] + +for n in range(0, 15): + most_common= Counter(sep).most_common(3) + likely_nums = [v[0] for v in most_common] + frequency = [v[-1] for v in most_common] + +Forecast = likely_nums[0] +Backups = str(" - ".join(likely_nums[1:])) +Chance = frac(1, 15) # Only one number is drawn out of 15 so every pick has the same chance + +#print(f"Likely number is . . . {Forecast} Backups: {Backups}\n" +#f"With percent chance of winning being {Chance}") + +d = dict(((k, eval (k)) for k in ('Forecast', 'Backups', 'Chance'))) +h = 'Forecast', 'Backups', 'Chance' +f = open('cp_ans.csv', 'w', encoding='utf_8') +writer = csv.DictWriter(f, fieldnames=h) +writer.writeheader() +writer.writerow(d) \ No newline at end of file diff --git a/cp_ans.csv b/cp_ans.csv new file mode 100644 index 0000000..ff8035f --- /dev/null +++ b/cp_ans.csv @@ -0,0 +1,2 @@ +Forecast,Backups,Chance +1,11 - 15,1/15 diff --git a/cron.txt b/cron.txt old mode 100644 new mode 100755 index 36a1a8f..c86bcb4 --- a/cron.txt +++ b/cron.txt @@ -1,11 +1,17 @@ - # Powerball -1 23 * * 1,3,6 +# Powerball +45 23 * * 1,3,6 # Mega Mil -0 23 * * 2,5 +50 23 * * 2,5 # Lotto America -31 22 * * 3,6 +0 23 * * 1,3,6 -# D3, D4, C25 (Every day but sunday 7:00) -0 19 * * 1,2,3,4,5,6 +# D3, D4 (Every day but sunday 7:45) +45 19 * * 1,2,3,4,5,6 + +# C25 (Mon, Tue, Thu, Fri 7:45) +45 19 * * 1,2,4,5 + +# Cash Pop (every hour 5:20 AM - 11:20 PM, lottery site is down 12-4 AM) +20 5-23 * * * diff --git a/d3_ans.csv b/d3_ans.csv old mode 100644 new mode 100755 index 350d9bb..6551fb3 --- a/d3_ans.csv +++ b/d3_ans.csv @@ -1,2 +1,2 @@ Forecast,Chance -0 - 7 - 8,163/7500 +3 - 7 - 8,3/500 diff --git a/d4_ans.csv b/d4_ans.csv old mode 100644 new mode 100755 index b7c7ffb..7d6d152 --- a/d4_ans.csv +++ b/d4_ans.csv @@ -1,2 +1,2 @@ Forecast,Chance -2 - 4 - 7 - 9,107/2000 +1 - 2 - 4 - 6,3/1250 diff --git a/daily3.py b/daily3.py index cd0f251..5871cf6 100755 --- a/daily3.py +++ b/daily3.py @@ -3,21 +3,30 @@ from fractions import Fraction as frac import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): - df_old = pd.read_excel('./excel_lotto_records/cash25.xlsx') + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games + df_old = pd.read_excel('./excel_lotto_records/daily3.xlsx') salvaged = df_old[['Date', 'Numbers']] - url = 'https://wvlottery.com/draw-games/daily-3/?game-analyze=daily-3&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=9&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", - "X-Requested-With": "XMLHttpRequest" } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) @@ -29,11 +38,14 @@ def get_data(): date, nums = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only keep actual digits, gets rid of any blanks from the excel records +sep = [x for x in sep if x.isdigit() and int(x) <= 9] for n in range(0, 10): most_common= Counter(sep).most_common(3) @@ -41,8 +53,9 @@ for n in range(0, 10): frequency = [v[-1] for v in most_common] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency) -Chance = frac(total_freq, 15000) # Chance = number call freq / all possible numbers i.e. 1000 +# Chance = playing the forecast as a box (any order), 3 different digits can come up 6 ways out of 1000 = 3/500 +# playing it straight (exact order) is 1/1000 +Chance = frac(6, 1000) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} \n" diff --git a/daily4.py b/daily4.py index 4175145..643e854 100755 --- a/daily4.py +++ b/daily4.py @@ -3,21 +3,30 @@ from fractions import Fraction as frac import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games df_old = pd.read_excel('./excel_lotto_records/daily4.xlsx') salvaged = df_old[['Date', 'Numbers']] - url = 'https://wvlottery.com/draw-games/daily-4/?game-analyze=daily-4&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=14&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", - "X-Requested-With": "XMLHttpRequest" } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) @@ -29,11 +38,14 @@ def get_data(): date, nums = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only keep actual digits, gets rid of any blanks from the excel records +sep = [x for x in sep if x.isdigit() and int(x) <= 9] for n in range(0, 9): most_common= Counter(sep).most_common(4) @@ -41,8 +53,9 @@ for n in range(0, 9): frequency = [v[-1] for v in most_common] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency) -Chance = frac(total_freq, 10000) # Chance = number call freq / all possible numbers i.e. 10000 +# Chance = playing the forecast as a box (any order), 4 different digits can come up 24 ways out of 10000 = 3/1250 +# playing it straight (exact order) is 1/10000 +Chance = frac(24, 10000) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} \n" diff --git a/dump.rdb b/dump.rdb old mode 100644 new mode 100755 diff --git a/excel_lotto_records/cash25.xlsx b/excel_lotto_records/cash25.xlsx old mode 100644 new mode 100755 diff --git a/excel_lotto_records/daily3.xlsx b/excel_lotto_records/daily3.xlsx old mode 100644 new mode 100755 diff --git a/excel_lotto_records/daily4.xlsx b/excel_lotto_records/daily4.xlsx old mode 100644 new mode 100755 diff --git a/excel_lotto_records/lotto.xlsx b/excel_lotto_records/lotto.xlsx old mode 100644 new mode 100755 diff --git a/excel_lotto_records/lotto_america.xlsx b/excel_lotto_records/lotto_america.xlsx old mode 100644 new mode 100755 diff --git a/excel_lotto_records/lotto_megamil.xlsx b/excel_lotto_records/lotto_megamil.xlsx old mode 100644 new mode 100755 diff --git a/la_ans.csv b/la_ans.csv old mode 100644 new mode 100755 index a3d678b..4c29ea5 --- a/la_ans.csv +++ b/la_ans.csv @@ -1,2 +1,2 @@ Forecast,SB,Chance -3 - 11 - 15 - 38 - 51,[9],43/6497400 +1 - 8 - 15 - 35 - 51,[4],1/25989600 diff --git a/lotto_america.py b/lotto_america.py index eea666a..026d89b 100755 --- a/lotto_america.py +++ b/lotto_america.py @@ -1,26 +1,38 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac +from math import comb import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games df_old = pd.read_excel('./excel_lotto_records/lotto_america.xlsx') salvaged = df_old[['Date', 'Numbers', 'SB']] - url = 'https://wvlottery.com/draw-games/lotto-america/?game-analyze=lotto-america&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=16&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { - "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/113.0", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': [], 'SB': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + web['SB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0]) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) - df2 = df[['Date', 'Numbers', 'SB', 'All Star']] + df2 = df[['Date', 'Numbers', 'SB']] date = list(df2['Date']) nums = list(df2['Numbers'].astype('str')) SBs = list(df2['SB'].astype('int')) @@ -29,11 +41,16 @@ def get_data(): date, nums, SBs = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only count numbers that can still be called, the ball ranges have changed over the years +# so the old records have some numbers that dont exist in the game anymore +sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 52] +SBs = [x for x in SBs if 1 <= x <= 10] for n in range(0, 52): most_common= Counter(sep).most_common(5) @@ -46,8 +63,9 @@ for n in range(0, 10): frequency_sb = [v[-1] for v in most_common_sb] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency + frequency_sb) -Chance = frac(total_freq, 25989600) # Chance = number call freq / all possible numbers i.e. 25,989,600 +# Chance = 1 / every possible ticket, 52 choose 5 white balls times 10 star balls = 25989600 +# every ticket has the same odds, the forecast just goes with the numbers that get called the most +Chance = frac(1, comb(52, 5) * 10) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} SB: {SB}\n" diff --git a/lottopy_pb.py b/lottopy_pb.py index 34183c1..910fddb 100755 --- a/lottopy_pb.py +++ b/lottopy_pb.py @@ -1,27 +1,38 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac +from math import comb import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games df_old = pd.read_excel('./excel_lotto_records/lotto.xlsx') - salvaged = df_old[['Date', 'Numbers', 'PB', 'PPX', 'Winners WV Only', 'Payout WV Only']] + salvaged = df_old[['Date', 'Numbers', 'PB']] - url = 'https://wvlottery.com/draw-games/powerball/?game-analyze=powerball&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=12&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", - "X-Requested-With": "XMLHttpRequest" } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': [], 'PB': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + web['PB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0]) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) - df2 = df[['Date', 'Numbers', 'PB', 'PPX', 'Winners WV Only', 'Payout WV Only']] + df2 = df[['Date', 'Numbers', 'PB']] date = list(df2['Date']) nums = list(df2['Numbers'].astype('str')) PBs = list(df2['PB'].astype('int')) @@ -30,11 +41,16 @@ def get_data(): date, nums, PBs = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only count numbers that can still be called, the ball ranges have changed over the years +# so the old records have some numbers that dont exist in the game anymore +sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 69] +PBs = [x for x in PBs if 1 <= x <= 26] for n in range(0, 69): most_common = Counter(sep).most_common(5) @@ -47,8 +63,9 @@ for n in range(0, 26): frequency_pb = [v[-1] for v in most_common_pb] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency + frequency_pb) -Chance = frac(total_freq, 292201338) # Chance = number call freq / all possible numbers i.e. 292201338 +# Chance = 1 / every possible ticket, 69 choose 5 white balls times 26 powerballs = 292201338 +# every ticket has the same odds, the forecast just goes with the numbers that get called the most +Chance = frac(1, comb(69, 5) * 26) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} PB: {PB}\n" diff --git a/megamil.py b/megamil.py index df56aad..16edf1d 100755 --- a/megamil.py +++ b/megamil.py @@ -1,28 +1,39 @@ # WVLottopy megamil: Matteo DiBiagio from fractions import Fraction as frac +from math import comb import pandas as pd import requests from collections import Counter -from io import StringIO import csv def get_data(): + # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games df_old = pd.read_excel('./excel_lotto_records/lotto_megamil.xlsx') salvaged = df_old[['Date', 'Numbers', 'MB']] - url = 'https://wvlottery.com/draw-games/mega-millions/?game-analyze=mega-millions&what-to-search=historysearch&date-range=-1' + url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=20&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", - "X-Requested-With": "XMLHttpRequest" } - r = requests.get(url, headers=header) - # Get web data - dfs = list(pd.read_html(StringIO(r.text))) + # Get web data, the new site pulls past draws from json 500 at a time + web = {'Date': [], 'Numbers': [], 'MB': []} + page = 0 + while True: + r = requests.get(url + str(page), headers=header) + data = r.json() + for x in data['content']: + web['Date'].append(x['drawingDate']) + web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) + web['MB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0]) + if data['last']: + break + page += 1 + dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records df = pd.concat([dfs[0], salvaged], ignore_index=True) - df2 = df[['Date', 'Numbers', 'MB', 'MP']] + df2 = df[['Date', 'Numbers', 'MB']] date = list(df2['Date']) nums = list(df2['Numbers'].astype('str')) MBs = list(df2['MB'].astype('int')) @@ -31,11 +42,16 @@ def get_data(): date, nums, MBs = get_data() # Formatting +# Site numbers come split by – and the excel records by - so it splits on both hyphenfree = [] for x in nums: - hyphenfree.append(x.replace('–',', ')) + hyphenfree.append(x.replace('–',', ').replace('-',', ')) splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") +# Only count numbers that can still be called, the ball ranges have changed over the years +# so the old records have some numbers that dont exist in the game anymore +sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 70] +MBs = [x for x in MBs if 1 <= x <= 24] for n in range(0, 70): most_common= Counter(sep).most_common(5) @@ -48,8 +64,9 @@ for n in range(0, 25): frequency_mb = [v[-1] for v in most_common_mb] sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) -total_freq = sum(frequency + frequency_mb) -Chance = frac(total_freq, 302575350) # Chance = number call freq / all possible numbers i.e. 11238513 +# Chance = 1 / every possible ticket, 70 choose 5 white balls times 24 mega balls = 290472336 +# every ticket has the same odds, the forecast just goes with the numbers that get called the most +Chance = frac(1, comb(70, 5) * 24) Forecast = str(" - ".join(sorted_nums)) #print(f"Likely numbers are . . . {Forecast} MB: {MB}\n" diff --git a/mm_ans.csv b/mm_ans.csv old mode 100644 new mode 100755 index d9f843a..5d0e5b7 --- a/mm_ans.csv +++ b/mm_ans.csv @@ -1,2 +1,2 @@ Forecast,MB,Chance -3 - 26 - 33 - 61 - 66,[7],43/100858450 +10 - 11 - 17 - 20 - 31,[7],1/290472336 diff --git a/pb_ans.csv b/pb_ans.csv old mode 100644 new mode 100755 index 51e5891..ac4b277 --- a/pb_ans.csv +++ b/pb_ans.csv @@ -1,2 +1,2 @@ Forecast,PB,Chance -19 - 24 - 27 - 33 - 64,[20],191/292201338 +16 - 23 - 27 - 28 - 32,[20],1/292201338 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 diff --git a/start.sh b/start.sh index 797d6c7..e4c9012 100755 --- a/start.sh +++ b/start.sh @@ -1 +1 @@ -echo "Powerball" && python lottopy_pb.py && echo "MegaMillions" && python megamil.py && echo "Lotto America" && python lotto_america.py && echo "Daily3" && python daily3.py && echo "Daily4" && python daily4.py && echo "Cash25" && python cash25.py +echo "Powerball" && python lottopy_pb.py && echo "MegaMillions" && python megamil.py && echo "Lotto America" && python lotto_america.py && echo "Daily3" && python daily3.py && echo "Daily4" && python daily4.py && echo "Cash25" && python cash25.py && echo "Cash Pop" && python cashpop.py