Compare commits

...
12 Commits
Author SHA1 Message Date
admin d634159947 merged the gitea history back in 2026-10-22 20:10:17 -04:00
admin f38609dfb9 switched to the new results api, added cash pop, excel records keep growing now and chance is fixed 2026-10-22 20:10:17 -04:00
xi-pinmping 66d0ba5b72 attempt at fixing browsers recognizing numbers as phone numbers on the website 2023-05-21 22:38:34 -04:00
admin 484983c554 fixed sorting 2023-01-02 12:35:52 -05:00
admin e15eff3bc1 replaced append with concat 2022-12-27 14:21:12 -05:00
admin 2ffee3f4c1 minor changes 2022-07-30 13:36:46 -04:00
admin 83700a4d4d fixed typos 2022-06-29 12:45:49 -04:00
admin 8e35d88d75 Added historical record analysis 2022-06-29 10:55:46 -04:00
admin 976f90a42c formatting changes 2022-06-15 17:46:18 -04:00
admin 8e20f1d7aa painful repo management 2022-06-15 17:43:06 -04:00
lottopy c559a947fb Delete README.md 2022-06-15 17:39:16 -04:00
lottopy 8cde725967 Initial commit 2022-06-12 11:45:23 -04:00
18 changed files with 597 additions and 488 deletions

No files matched your search

+4 -23
View File
@@ -1,24 +1,5 @@
# Python
__pycache__/ __pycache__/
*.py[cod] *.pre-recording
.venv/ *.pre-ny-backfill
venv/ .*.lock
env/ *.tmp.xlsx
# Output from the scripts
*_ans.csv
*.log
# Secrets and local config
.env
.env.*
*.pem
*.key
secrets.py
# Editor junk
.vscode/
.idea/
*.swp
*~
.DS_Store
+7 -7
View File
@@ -8,14 +8,14 @@ Previously there were records dating back to 1992 that were removed by the websi
I am welcoming anyone who wants to to port it to their own state/country to do so. I currently have a website www.wvlotterypredictor.xyz hosting my numbers to be refreshed daily. Collaboration and suggestion to a more accurate algorithm is also welcome. I can be contacted about the project through my site email, on here, or on the Twitter linked on my site. I am welcoming anyone who wants to to port it to their own state/country to do so. I currently have a website www.wvlotterypredictor.xyz hosting my numbers to be refreshed daily. Collaboration and suggestion to a more accurate algorithm is also welcome. I can be contacted about the project through my site email, on here, or on the Twitter linked on my site.
# How the site works
- Each game has its own script. It pulls every past draw from the WV Lottery results api (the same one wvlottery.com uses for its past draws page), adds the older records from the excel files where there are any, and counts how often each number has been drawn. The chance shown is the actual odds of that ticket hitting, every ticket has the same odds so the forecast is just going with the numbers that have been called the most.
- On the site the scripts write their numbers to a csv instead of printing them. cron runs each one about 45 minutes after that game's drawing so the new numbers are already posted.
- The site itself is Django served by gunicorn behind nginx. It reads the csv files for the home page and caches the page in redis, which gets cleared every hour.
# Good luck! # Good luck!
# CHANGELOG # CHANGELOG
- September 26th 2026: wvlottery.com was rebuilt and the old history tables are gone, so every script now pulls past draws from the json results api the new site uses. Added Cash Pop. Updated Mega Millions odds for the 2025 changes.
- September 26th 2026 (later): The excel records were never actually getting counted (they use - and the site used –), they are now. Numbers that cant be drawn anymore since the ball ranges changed get skipped. Chance is now the real odds of the forecast ticket winning instead of the frequency number, Daily3 and Daily4 are the odds for a box play.
- June 29th 2022: Added support for old data that was previously scrubbed from the lottery site. It is more accurate and includes more data than the previous one. Chance for daily3 is now bugged however due to the large amount of numbers and dates. This will be fixed soon. - June 29th 2022: Added support for old data that was previously scrubbed from the lottery site. It is more accurate and includes more data than the previous one. Chance for daily3 is now bugged however due to the large amount of numbers and dates. This will be fixed soon.
- October 2026: wvlottery.com moved their past results to a new api so the scripts pull from that now. Added Cash Pop. The site only keeps about 3 years of draws (Cash Pop only 1) so records.py adds every new draw to the excel sheets when a script runs, that way the history keeps growing instead of getting lost again. Chance is now the actual odds of the ticket, which also fixes daily3.
# TODO:
- Nothing right now, suggestions welcome
+65 -64
View File
@@ -1,64 +1,65 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
from math import comb from math import comb
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data(): def get_data():
# old data from WVLottery.com # 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') df_old = pd.read_excel('./excel_lotto_records/cash25.xlsx')
salvaged = df_old[['Date', 'Numbers']] salvaged = df_old[['Date', 'Numbers']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=10&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=10&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = { header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", "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, the new site pulls past draws from json 500 at a time # Get web data, the new site pulls past draws from json 500 at a time
web = {'Date': [], 'Numbers': []} web = {'Date': [], 'Numbers': []}
page = 0 page = 0
while True: while True:
r = requests.get(url + str(page), headers=header) r = requests.get(url + str(page), headers=header)
data = r.json() data = r.json()
for x in data['content']: for x in data['content']:
web['Date'].append(x['drawingDate']) web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
if data['last']: if data['last']:
break break
page += 1 page += 1
dfs = [pd.DataFrame(web)] dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None) pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records # Specifies no max rows, otherwise only shows 10 records
df = pd.concat([dfs[0], salvaged], ignore_index=True) # Adds any draw not in the sheet yet, so the excel record keeps growing
df2 = df[['Date', 'Numbers']] df = records.merge_save('./excel_lotto_records/cash25.xlsx', dfs[0], fallback=salvaged)
date = list(df2['Date']) df2 = df[['Date', 'Numbers']]
nums = list(df2['Numbers'].astype('str')) date = list(df2['Date'])
return date, nums nums = list(df2['Numbers'].astype('str'))
return date, nums
date, nums = get_data()
date, nums = get_data()
# Formatting
# Site numbers come split by – and the excel records by - so it splits on both # Formatting
hyphenfree = [] # Site numbers come split by – and the excel records by - so it splits on both
for x in nums: hyphenfree = []
hyphenfree.append(x.replace('–',', ').replace('-',', ')) for x in nums:
splitlist = ", ".join(hyphenfree) hyphenfree.append(x.replace('–',', ').replace('-',', '))
sep = splitlist.split(", ") splitlist = ", ".join(hyphenfree)
# Only count numbers that can still be called, the ball ranges have changed over the years sep = splitlist.split(", ")
# so the old records have some numbers that dont exist in the game anymore # Only count numbers that can still be called, the ball ranges have changed over the years
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 25] # 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) for n in range(0, 25):
likely_nums = [v[0] for v in most_common] most_common= Counter(sep).most_common(6)
frequency = [v[-1] for v in most_common] likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = 1 / every possible ticket, 25 choose 6 = 177100 sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# every ticket has the same odds, the forecast just goes with the numbers that get called the most # Chance = 1 / every possible ticket, 25 choose 6 = 177100
Chance = frac(1, comb(25, 6)) # every ticket has the same odds, the forecast just goes with the numbers that get called the most
Forecast = str(" - ".join(sorted_nums)) Chance = frac(1, comb(25, 6))
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}") print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}")
+56 -50
View File
@@ -1,50 +1,56 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
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=' def get_data():
header = { url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=24&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", 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': []} # Get web data, cash pop draws every 15 min so only use the last ~3000 draws (about a month)
page = 0 web = {'Date': [], 'Numbers': []}
while page < 6: ids, times = [], []
r = requests.get(url + str(page), headers=header) page = 0
data = r.json() while page < 6:
for x in data['content']: r = requests.get(url + str(page), headers=header)
web['Date'].append(x['drawingDate']) data = r.json()
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) for x in data['content']:
if data['last']: web['Date'].append(records.draw_day(x))
break web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
page += 1 ids.append(x['externalId'])
df2 = pd.DataFrame(web) times.append(x['drawDate'])
date = list(df2['Date']) if data['last']:
nums = list(df2['Numbers'].astype('str')) break
return date, nums page += 1
df2 = pd.DataFrame(web)
date, nums = get_data() # The site only keeps a year of cash pop draws, keep our own record of every draw
records.merge_save('./excel_lotto_records/cash_pop.xlsx', df2, ids=ids, times=times)
# Formatting date = list(df2['Date'])
hyphenfree = [] nums = list(df2['Numbers'].astype('str'))
for x in nums: return date, nums
hyphenfree.append(x.replace('–',', '))
splitlist = ", ".join(hyphenfree) date, nums = get_data()
sep = splitlist.split(", ")
# Only keep 1 - 15, just in case anything weird comes back from the site # Formatting
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 15] hyphenfree = []
for x in nums:
for n in range(0, 15): hyphenfree.append(x.replace('–',', '))
most_common= Counter(sep).most_common(3) splitlist = ", ".join(hyphenfree)
likely_nums = [v[0] for v in most_common] sep = splitlist.split(", ")
frequency = [v[-1] for v in most_common] # 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]
Forecast = likely_nums[0]
Backups = str(" - ".join(likely_nums[1:])) for n in range(0, 15):
Chance = frac(1, 15) # Only one number is drawn out of 15 so every pick has the same chance most_common= Counter(sep).most_common(3)
likely_nums = [v[0] for v in most_common]
print(f"Likely number is . . . {Forecast} Backups: {Backups}\n" frequency = [v[-1] for v in most_common]
f"With percent chance of winning being {Chance}")
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}")
+63 -62
View File
@@ -1,62 +1,63 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data(): 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 # 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') df_old = pd.read_excel('./excel_lotto_records/daily3.xlsx')
salvaged = df_old[['Date', 'Numbers']] salvaged = df_old[['Date', 'Numbers']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=9&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=9&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = { header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", "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, the new site pulls past draws from json 500 at a time # Get web data, the new site pulls past draws from json 500 at a time
web = {'Date': [], 'Numbers': []} web = {'Date': [], 'Numbers': []}
page = 0 page = 0
while True: while True:
r = requests.get(url + str(page), headers=header) r = requests.get(url + str(page), headers=header)
data = r.json() data = r.json()
for x in data['content']: for x in data['content']:
web['Date'].append(x['drawingDate']) web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
if data['last']: if data['last']:
break break
page += 1 page += 1
dfs = [pd.DataFrame(web)] dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None) pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records # Specifies no max rows, otherwise only shows 10 records
df = pd.concat([dfs[0], salvaged], ignore_index=True) # Adds any draw not in the sheet yet, so the excel record keeps growing
df2 = df[['Date', 'Numbers']] df = records.merge_save('./excel_lotto_records/daily3.xlsx', dfs[0], fallback=salvaged)
date = list(df2['Date']) df2 = df[['Date', 'Numbers']]
nums = list(df2['Numbers'].astype('str')) date = list(df2['Date'])
return date, nums nums = list(df2['Numbers'].astype('str'))
return date, nums
date, nums = get_data()
date, nums = get_data()
# Formatting
# Site numbers come split by – and the excel records by - so it splits on both # Formatting
hyphenfree = [] # Site numbers come split by – and the excel records by - so it splits on both
for x in nums: hyphenfree = []
hyphenfree.append(x.replace('–',', ').replace('-',', ')) for x in nums:
splitlist = ", ".join(hyphenfree) hyphenfree.append(x.replace('–',', ').replace('-',', '))
sep = splitlist.split(", ") splitlist = ", ".join(hyphenfree)
# Only keep actual digits, gets rid of any blanks from the excel records sep = splitlist.split(", ")
sep = [x for x in sep if x.isdigit() and int(x) <= 9] # 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) for n in range(0, 10):
likely_nums = [v[0] for v in most_common] most_common= Counter(sep).most_common(3)
frequency = [v[-1] for v in most_common] likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = playing the forecast as a box (any order), 3 different digits can come up 6 ways out of 1000 = 3/500 sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# playing it straight (exact order) is 1/1000 # Chance = playing the forecast as a box (any order), 3 different digits can come up 6 ways out of 1000 = 3/500
Chance = frac(6, 1000) # playing it straight (exact order) is 1/1000
Forecast = str(" - ".join(sorted_nums)) Chance = frac(6, 1000)
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}") print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}")
+63 -62
View File
@@ -1,62 +1,63 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data(): def get_data():
# Old data from WVLottery.com # 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') df_old = pd.read_excel('./excel_lotto_records/daily4.xlsx')
salvaged = df_old[['Date', 'Numbers']] salvaged = df_old[['Date', 'Numbers']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=14&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=14&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = { header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", "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, the new site pulls past draws from json 500 at a time # Get web data, the new site pulls past draws from json 500 at a time
web = {'Date': [], 'Numbers': []} web = {'Date': [], 'Numbers': []}
page = 0 page = 0
while True: while True:
r = requests.get(url + str(page), headers=header) r = requests.get(url + str(page), headers=header)
data = r.json() data = r.json()
for x in data['content']: for x in data['content']:
web['Date'].append(x['drawingDate']) web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
if data['last']: if data['last']:
break break
page += 1 page += 1
dfs = [pd.DataFrame(web)] dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None) pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records # Specifies no max rows, otherwise only shows 10 records
df = pd.concat([dfs[0], salvaged], ignore_index=True) # Adds any draw not in the sheet yet, so the excel record keeps growing
df2 = df[['Date', 'Numbers']] df = records.merge_save('./excel_lotto_records/daily4.xlsx', dfs[0], fallback=salvaged)
date = list(df2['Date']) df2 = df[['Date', 'Numbers']]
nums = list(df2['Numbers'].astype('str')) date = list(df2['Date'])
return date, nums nums = list(df2['Numbers'].astype('str'))
return date, nums
date, nums = get_data()
date, nums = get_data()
# Formatting
# Site numbers come split by – and the excel records by - so it splits on both # Formatting
hyphenfree = [] # Site numbers come split by – and the excel records by - so it splits on both
for x in nums: hyphenfree = []
hyphenfree.append(x.replace('–',', ').replace('-',', ')) for x in nums:
splitlist = ", ".join(hyphenfree) hyphenfree.append(x.replace('–',', ').replace('-',', '))
sep = splitlist.split(", ") splitlist = ", ".join(hyphenfree)
# Only keep actual digits, gets rid of any blanks from the excel records sep = splitlist.split(", ")
sep = [x for x in sep if x.isdigit() and int(x) <= 9] # 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) for n in range(0, 9):
likely_nums = [v[0] for v in most_common] most_common= Counter(sep).most_common(4)
frequency = [v[-1] for v in most_common] likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = playing the forecast as a box (any order), 4 different digits can come up 24 ways out of 10000 = 3/1250 sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# playing it straight (exact order) is 1/10000 # Chance = playing the forecast as a box (any order), 4 different digits can come up 24 ways out of 10000 = 3/1250
Chance = frac(24, 10000) # playing it straight (exact order) is 1/10000
Forecast = str(" - ".join(sorted_nums)) Chance = frac(24, 10000)
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}") print(f"Likely numbers are . . . {Forecast} \n"
f"With percent chance of winning being {Chance}")
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+73 -72
View File
@@ -1,72 +1,73 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
from math import comb from math import comb
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data(): 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 # 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') df_old = pd.read_excel('./excel_lotto_records/lotto_america.xlsx')
salvaged = df_old[['Date', 'Numbers', 'SB']] salvaged = df_old[['Date', 'Numbers', 'SB']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=16&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=16&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = { header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", "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, the new site pulls past draws from json 500 at a time # Get web data, the new site pulls past draws from json 500 at a time
web = {'Date': [], 'Numbers': [], 'SB': []} web = {'Date': [], 'Numbers': [], 'SB': []}
page = 0 page = 0
while True: while True:
r = requests.get(url + str(page), headers=header) r = requests.get(url + str(page), headers=header)
data = r.json() data = r.json()
for x in data['content']: for x in data['content']:
web['Date'].append(x['drawingDate']) web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) 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]) web['SB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0])
if data['last']: if data['last']:
break break
page += 1 page += 1
dfs = [pd.DataFrame(web)] dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None) pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records # Specifies no max rows, otherwise only shows 10 records
df = pd.concat([dfs[0], salvaged], ignore_index=True) # Adds any draw not in the sheet yet, so the excel record keeps growing
df2 = df[['Date', 'Numbers', 'SB']] df = records.merge_save('./excel_lotto_records/lotto_america.xlsx', dfs[0], fallback=salvaged)
date = list(df2['Date']) df2 = df[['Date', 'Numbers', 'SB']]
nums = list(df2['Numbers'].astype('str')) date = list(df2['Date'])
SBs = list(df2['SB'].astype('int')) nums = list(df2['Numbers'].astype('str'))
return date, nums, SBs SBs = list(df2['SB'].astype('int'))
return date, nums, SBs
date, nums, SBs = get_data()
date, nums, SBs = get_data()
# Formatting
# Site numbers come split by – and the excel records by - so it splits on both # Formatting
hyphenfree = [] # Site numbers come split by – and the excel records by - so it splits on both
for x in nums: hyphenfree = []
hyphenfree.append(x.replace('–',', ').replace('-',', ')) for x in nums:
splitlist = ", ".join(hyphenfree) hyphenfree.append(x.replace('–',', ').replace('-',', '))
sep = splitlist.split(", ") splitlist = ", ".join(hyphenfree)
# Only count numbers that can still be called, the ball ranges have changed over the years sep = splitlist.split(", ")
# so the old records have some numbers that dont exist in the game anymore # Only count numbers that can still be called, the ball ranges have changed over the years
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 52] # so the old records have some numbers that dont exist in the game anymore
SBs = [x for x in SBs if 1 <= x <= 10] 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) for n in range(0, 52):
likely_nums = [v[0] for v in most_common] most_common= Counter(sep).most_common(5)
frequency = [v[-1] for v in most_common] likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
for n in range(0, 10):
most_common_sb = Counter(SBs).most_common(1) for n in range(0, 10):
SB = [v[0] for v in most_common_sb] most_common_sb = Counter(SBs).most_common(1)
frequency_sb = [v[-1] for v in most_common_sb] SB = [v[0] for v in most_common_sb]
frequency_sb = [v[-1] for v in most_common_sb]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = 1 / every possible ticket, 52 choose 5 white balls times 10 star balls = 25989600 sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# every ticket has the same odds, the forecast just goes with the numbers that get called the most # Chance = 1 / every possible ticket, 52 choose 5 white balls times 10 star balls = 25989600
Chance = frac(1, comb(52, 5) * 10) # every ticket has the same odds, the forecast just goes with the numbers that get called the most
Forecast = str(" - ".join(sorted_nums)) Chance = frac(1, comb(52, 5) * 10)
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} SB: {SB}\n"
f"With percent chance of winning being {Chance}") print(f"Likely numbers are . . . {Forecast} SB: {SB}\n"
f"With percent chance of winning being {Chance}")
+73 -73
View File
@@ -1,73 +1,73 @@
# WVLottopy: Matteo DiBiagio # WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
from math import comb from math import comb
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data(): def get_data():
# previous records which have since been removed from wvlottery.com's database # 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') df_old = pd.read_excel('./excel_lotto_records/lotto.xlsx')
salvaged = df_old[['Date', 'Numbers', 'PB']] salvaged = df_old[['Date', 'Numbers', 'PB']]
# Current web records url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=12&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=12&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page=' header = {
header = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36",
"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, the new site pulls past draws from json 500 at a time
# Get web data, the new site pulls past draws from json 500 at a time web = {'Date': [], 'Numbers': [], 'PB': []}
web = {'Date': [], 'Numbers': [], 'PB': []} page = 0
page = 0 while True:
while True: r = requests.get(url + str(page), headers=header)
r = requests.get(url + str(page), headers=header) data = r.json()
data = r.json() for x in data['content']:
for x in data['content']: web['Date'].append(records.draw_day(x))
web['Date'].append(x['drawingDate']) web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
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])
web['PB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0]) if data['last']:
if data['last']: break
break page += 1
page += 1 dfs = [pd.DataFrame(web)]
dfs = [pd.DataFrame(web)] pd.set_option('display.max_rows', None)
pd.set_option('display.max_rows', None) # Specifies no max rows, otherwise only shows 10 records
# Specifies no max rows, otherwise only shows 10 records # Adds any draw not in the sheet yet, so the excel record keeps growing
df = pd.concat([dfs[0], salvaged], ignore_index=True) df = records.merge_save('./excel_lotto_records/lotto.xlsx', dfs[0], fallback=salvaged)
df2 = df[['Date', 'Numbers', 'PB']] df2 = df[['Date', 'Numbers', 'PB']]
date = list(df2['Date']) date = list(df2['Date'])
nums = list(df2['Numbers'].astype('str')) nums = list(df2['Numbers'].astype('str'))
PBs = list(df2['PB'].astype('int')) PBs = list(df2['PB'].astype('int'))
return date, nums, PBs return date, nums, PBs
date, nums, PBs = get_data() date, nums, PBs = get_data()
# Formatting # Formatting
# Site numbers come split by – and the excel records by - so it splits on both # Site numbers come split by – and the excel records by - so it splits on both
hyphenfree = [] hyphenfree = []
for x in nums: for x in nums:
hyphenfree.append(x.replace('–',', ').replace('-',', ')) hyphenfree.append(x.replace('–',', ').replace('-',', '))
splitlist = ", ".join(hyphenfree) splitlist = ", ".join(hyphenfree)
sep = splitlist.split(", ") sep = splitlist.split(", ")
# Only count numbers that can still be called, the ball ranges have changed over the years # 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 # 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] sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 69]
PBs = [x for x in PBs if 1 <= x <= 26] PBs = [x for x in PBs if 1 <= x <= 26]
for n in range(0, 69): for n in range(0, 69):
most_common = Counter(sep).most_common(5) most_common = Counter(sep).most_common(5)
likely_nums = [v[0] for v in most_common] likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common] frequency = [v[-1] for v in most_common]
for n in range(0, 26): for n in range(0, 26):
most_common_pb = Counter(PBs).most_common(1) most_common_pb = Counter(PBs).most_common(1)
PB = [v[0] for v in most_common_pb] PB = [v[0] for v in most_common_pb]
frequency_pb = [v[-1] for v in most_common_pb] frequency_pb = [v[-1] for v in most_common_pb]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = 1 / every possible ticket, 69 choose 5 white balls times 26 powerballs = 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 # 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) Chance = frac(1, comb(69, 5) * 26)
Forecast = str(" - ".join(sorted_nums)) Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} PB: {PB}\n" print(f"Likely numbers are . . . {Forecast} PB: {PB}\n"
f"With percent chance of winning being {Chance}") f"With percent chance of winning being {Chance}")
+74 -72
View File
@@ -1,72 +1,74 @@
# WVLottopy megamil: Matteo DiBiagio # WVLottopy megamil: Matteo DiBiagio
from fractions import Fraction as frac from fractions import Fraction as frac
from math import comb from math import comb
import pandas as pd import pandas as pd
import requests import records
from collections import Counter import requests
from collections import Counter
def get_data():
# previous records which have since been removed from wvlottery.com's database def get_data():
df_old = pd.read_excel('./excel_lotto_records/lotto_megamil.xlsx') # Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games
salvaged = df_old[['Date', 'Numbers', 'MB']] df_old = pd.read_excel('./excel_lotto_records/lotto_megamil.xlsx')
salvaged = df_old[['Date', 'Numbers', 'MB']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=20&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = { url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=20&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36", 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, the new site pulls past draws from json 500 at a time }
web = {'Date': [], 'Numbers': [], 'MB': []} # Get web data, the new site pulls past draws from json 500 at a time
page = 0 web = {'Date': [], 'Numbers': [], 'MB': []}
while True: page = 0
r = requests.get(url + str(page), headers=header) while True:
data = r.json() r = requests.get(url + str(page), headers=header)
for x in data['content']: data = r.json()
web['Date'].append(x['drawingDate']) for x in data['content']:
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR')) web['Date'].append(records.draw_day(x))
web['MB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0]) web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
if data['last']: web['MB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0])
break if data['last']:
page += 1 break
dfs = [pd.DataFrame(web)] page += 1
pd.set_option('display.max_rows', None) dfs = [pd.DataFrame(web)]
# Specifies no max rows, otherwise only shows 10 records pd.set_option('display.max_rows', None)
df = pd.concat([dfs[0], salvaged], ignore_index=True) # Specifies no max rows, otherwise only shows 10 records
df2 = df[['Date', 'Numbers', 'MB']] # Adds any draw not in the sheet yet, so the excel record keeps growing
date = list(df2['Date']) df = records.merge_save('./excel_lotto_records/lotto_megamil.xlsx', dfs[0], fallback=salvaged)
nums = list(df2['Numbers'].astype('str')) df2 = df[['Date', 'Numbers', 'MB']]
MBs = list(df2['MB'].astype('int')) date = list(df2['Date'])
return date, nums, MBs nums = list(df2['Numbers'].astype('str'))
MBs = list(df2['MB'].astype('int'))
date, nums, MBs = get_data() return date, nums, MBs
# Formatting date, nums, MBs = get_data()
# Site numbers come split by – and the excel records by - so it splits on both
hyphenfree = [] # Formatting
for x in nums: # Site numbers come split by – and the excel records by - so it splits on both
hyphenfree.append(x.replace('–',', ').replace('-',', ')) hyphenfree = []
splitlist = ", ".join(hyphenfree) for x in nums:
sep = splitlist.split(", ") hyphenfree.append(x.replace('–',', ').replace('-',', '))
# Only count numbers that can still be called, the ball ranges have changed over the years splitlist = ", ".join(hyphenfree)
# so the old records have some numbers that dont exist in the game anymore sep = splitlist.split(", ")
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 70] # Only count numbers that can still be called, the ball ranges have changed over the years
MBs = [x for x in MBs if 1 <= x <= 24] # 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]
for n in range(0, 70): MBs = [x for x in MBs if 1 <= x <= 24]
most_common= Counter(sep).most_common(5)
likely_nums = [v[0] for v in most_common] for n in range(0, 70):
frequency = [v[-1] for v in most_common] most_common= Counter(sep).most_common(5)
likely_nums = [v[0] for v in most_common]
for n in range(0, 25): frequency = [v[-1] for v in most_common]
most_common_mb = Counter(MBs).most_common(1)
MB = [v[0] for v in most_common_mb] for n in range(0, 25):
frequency_mb = [v[-1] for v in most_common_mb] most_common_mb = Counter(MBs).most_common(1)
MB = [v[0] for v in most_common_mb]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x)) frequency_mb = [v[-1] for v in most_common_mb]
# 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 sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
Chance = frac(1, comb(70, 5) * 24) # Chance = 1 / every possible ticket, 70 choose 5 white balls times 24 mega balls = 290472336
Forecast = str(" - ".join(sorted_nums)) # 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)
print(f"Likely numbers are . . . {Forecast} MB: {MB}\n" Forecast = str(" - ".join(sorted_nums))
f"With percent chance of winning being {Chance}")
print(f"Likely numbers are . . . {Forecast} MB: {MB}\n"
f"With percent chance of winning being {Chance}")
+116
View File
@@ -0,0 +1,116 @@
# WVLottopy: Matteo DiBiagio
# wvlottery.com only keeps about 3 years of results (cash pop only 1) so this adds every new draw
# to the excel sheets each run, that way the records keep growing instead of getting lost again.
# Nothing already in the sheets gets changed or removed.
import fcntl
import os
import shutil
from collections import Counter
import pandas as pd
def draw_day(x):
# drawingDate from the site is in UTC so the late draws (powerball, megamillions, lotto america)
# show up a day late, converting drawDate to eastern time gives the real day
try:
from datetime import datetime
from zoneinfo import ZoneInfo
t = datetime.fromisoformat(str(x['drawDate']).replace('Z', '+00:00'))
return t.astimezone(ZoneInfo('America/New_York')).strftime('%Y-%m-%d')
except Exception:
return x['drawingDate']
def _fmt_date(d):
# site dates are 2026-10-09, the sheets use 10/09/2026
s = str(d)[:10]
if len(s) == 10 and s[4] == '-':
return f'{s[5:7]}/{s[8:10]}/{s[0:4]}'
return s
def _fmt_nums(n):
# site splits numbers with – and the sheets use -
return str(n).replace('–', '-').strip()
def _newer_first(df):
# some of the sheets are newest first and some are oldest first
d = pd.to_datetime(df['Date'], errors='coerce').dropna()
return len(d) > 1 and d.iloc[0] > d.iloc[-1]
def merge_save(path, web_df, fallback=None, ids=None, times=None):
# if saving fails for whatever reason just use the site + old sheet so the numbers still come out
try:
return _merge_save(path, web_df, ids, times)
except Exception as e:
print(f'records: could not update {os.path.basename(path)}: {e!r}')
if fallback is not None:
return pd.concat([web_df, fallback], ignore_index=True)
return None
def _merge_save(path, web_df, ids=None, times=None):
# web_df is Date, Numbers and the bonus ball column if the game has one
# ids is the site's draw id for each row (cash pop needs it), returns the whole sheet
bonus = [c for c in web_df.columns if c not in ('Date', 'Numbers')]
if os.path.exists(path):
old = pd.read_excel(path)
else:
old = pd.DataFrame(columns=['Unnamed: 0', 'Date', 'Numbers'] + bonus)
if len(web_df) == 0:
return old[['Date', 'Numbers'] + bonus].copy()
web = web_df.copy()
web['Date'] = web['Date'].map(_fmt_date)
web['Numbers'] = web['Numbers'].map(_fmt_nums)
if ids is not None:
web['DrawID'] = [str(i) for i in ids]
if times is not None:
web['DrawTime'] = [str(t) for t in times]
def key(r):
return (str(r['Date']), _fmt_nums(r['Numbers'])) + tuple(str(int(r[c])) if str(r[c]) not in ('nan', 'None', '') else '' for c in bonus)
# rows with a draw id get matched by the id, date + numbers is only for the old rows without one
# (cash pop draws 1 number out of 15 like 90 times a day so the same date + number happens a lot)
have_ids = set(old['DrawID'].dropna().astype(str)) if 'DrawID' in old.columns else set()
no_id = old['DrawID'].isna() if 'DrawID' in old.columns else pd.Series(True, index=old.index)
have = Counter(key(r) for _, r in old[no_id].iterrows())
keep = []
for _, r in web.iterrows():
if 'DrawID' in web.columns and str(r['DrawID']) in have_ids:
continue
k = key(r)
if have[k] > 0:
have[k] -= 1
continue
keep.append(r)
new = pd.DataFrame(keep, columns=web.columns)
if len(new):
lock = open(os.path.join(os.path.dirname(path) or '.', '.' + os.path.basename(path) + '.lock'), 'w')
fcntl.flock(lock, fcntl.LOCK_EX)
try:
# one time backup of the sheet before it ever gets added to
backup = path + '.pre-recording'
if os.path.exists(path) and not os.path.exists(backup):
shutil.copy2(path, backup)
new['_d'] = pd.to_datetime(new['Date'], errors='coerce')
desc = _newer_first(old) if len(old) else True
new = new.sort_values('_d', ascending=not desc, kind='stable').drop(columns='_d')
start = int(pd.to_numeric(old['Unnamed: 0'], errors='coerce').max() + 1) if len(old) and 'Unnamed: 0' in old.columns else 0
new.insert(0, 'Unnamed: 0', range(start, start + len(new)))
full = pd.concat([new, old], ignore_index=True) if desc else pd.concat([old, new], ignore_index=True)
tmp = path[:-5] + '.tmp.xlsx'
full.to_excel(tmp, index=False, engine='openpyxl')
os.replace(tmp, path)
finally:
fcntl.flock(lock, fcntl.LOCK_UN)
lock.close()
print(f'records: {os.path.basename(path)} +{len(new)} new draws')
else:
full = old
return full[['Date', 'Numbers'] + bonus].copy()
+3 -3
View File
@@ -1,3 +1,3 @@
pandas==1.3.5 pandas>=2.0
requests==2.26.0 requests>=2.31
openpyxl openpyxl>=3.1