From 54fc31df0d2fa7ee6a73193843a7170e84321645 Mon Sep 17 00:00:00 2001 From: lottopy Date: Mon, 13 Jun 2022 02:55:06 -0400 Subject: [PATCH] Initial refactoring and optimizations --- .gitignore | 2 ++ README.md | 9 +++--- c25_ans.csv | 2 +- cash25.py | 71 ++++++++++++++------------------------------- d3_ans.csv | 2 +- d4_ans.csv | 2 +- daily3.py | 71 +++++++++++++-------------------------------- daily4.py | 72 ++++++++++++++-------------------------------- la_ans.csv | 2 +- lotto_america.py | 75 +++++++++++++++++------------------------------- lottopy_pb.py | 72 ++++++++++++++-------------------------------- megamil.py | 72 ++++++++++++++++------------------------------ requirements.txt | 3 +- smartscraper.py | 73 ---------------------------------------------- 14 files changed, 147 insertions(+), 381 deletions(-) create mode 100644 .gitignore delete mode 100755 smartscraper.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cf25ad --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Excel +*.xlsx diff --git a/README.md b/README.md index 2fd9a10..1646d1d 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ -WVLotto.py +lotto.py -This script generates the five most likely lottery numbers and one powerball, based off frequency pulled. +This script generates the most likely lottery numbers based off frequency of winning numbers. -This script uses an excel sheet to store the history of all WV Lottery numbers since 1992. It does NOT however guarantee you will win. +Previously there were records dating back to 1992 that were removed by the website, which has lead me to rewrite and encourage the collaboration and sharing of this work. + +I am welcoming anyone who wants to to port it to their own state to do so. I currently have a website hosting my numbers to be refreshed daily. Collaboration and suggestion at a more accurate algorithm is also welcome. Good luck! -# lottopy_web_edition diff --git a/c25_ans.csv b/c25_ans.csv index f1d7492..af12903 100644 --- a/c25_ans.csv +++ b/c25_ans.csv @@ -1,2 +1,2 @@ Winning_Numbers,Chance -14-18-2-22-5-9,49/25300 +14-18-2-22-5-9,31/16100 diff --git a/cash25.py b/cash25.py index f6539c3..fa43f02 100755 --- a/cash25.py +++ b/cash25.py @@ -1,55 +1,29 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -url = 'https://wvlottery.com/draw-games/cash-25/?game-analyze=cash-25&what-to-search=historysearch&date-range=-1' -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" -} +def get_data(): + url = 'https://wvlottery.com/draw-games/cash-25/?game-analyze=cash-25&what-to-search=historysearch&date-range=-1' + 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" + } -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers']] -# Print Table -#print(df2) + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + return date, nums -# To excel file -df2.to_excel('./cash25.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("cash25.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -#PB = list(df['PB'].astype('int')) -#appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='cash25.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='cash25.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums = get_data() # Formatting hyphenfree = [] @@ -62,18 +36,15 @@ for n in range(0, 25): most_common= Counter(sep).most_common(6) likely_nums = [v[0] for v in most_common] frequency = [v[-1] for v in most_common] - -#for n in range(0, 26): -# most_common_pb = Counter(PB).most_common(1) -# likely_pb = [v[0] for v in most_common_pb] -# frequency_pb = [v[-1] for v in most_common_pb] sorted_nums = sorted(likely_nums) total_freq = sum(frequency) -Chance = frac(total_freq, 177100) # Chance = number call freq / all possible numbers i.e. 11238513 +Chance = frac(total_freq, 177100) # Chance = number call freq / all possible numbers i.e. 177100 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers} \n" +#f"With percent chance of winning being {Chance}") + d = dict(((k, eval (k)) for k in ('Winning_Numbers','Chance'))) h = 'Winning_Numbers', 'Chance' f = open('c25_ans.csv', 'w', encoding='utf_8') diff --git a/d3_ans.csv b/d3_ans.csv index e57f1b1..149ec44 100644 --- a/d3_ans.csv +++ b/d3_ans.csv @@ -1,2 +1,2 @@ Winning_Numbers,Chance -0-3-8,33/10000 +0-3-8,3/100 diff --git a/d4_ans.csv b/d4_ans.csv index 3e7a8cc..1ee53bf 100644 --- a/d4_ans.csv +++ b/d4_ans.csv @@ -1,2 +1,2 @@ Winning_Numbers,Chance -3-5-6-8,537/10000 +3-5-6-8,67/1250 diff --git a/daily3.py b/daily3.py index 7110d3d..c1afec2 100755 --- a/daily3.py +++ b/daily3.py @@ -1,55 +1,28 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -url = 'https://wvlottery.com/draw-games/daily-3/?game-analyze=daily-3&what-to-search=historysearch&date-range=1' -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" -} +def get_data(): + url = 'https://wvlottery.com/draw-games/daily-3/?game-analyze=daily-3&what-to-search=historysearch&date-range=1' + 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" + } + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + return date, nums -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers']] -# Print Table -#print(df2) - -# To excel file -df2.to_excel('./daily3.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("daily3.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -#PB = list(df['PB'].astype('int')) -#appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -#index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='daily3.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='daily3.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums = get_data() # Formatting hyphenfree = [] @@ -62,18 +35,14 @@ for n in range(0, 10): most_common= Counter(sep).most_common(3) likely_nums = [v[0] for v in most_common] frequency = [v[-1] for v in most_common] - -#for n in range(0, 26): -# most_common_pb = Counter(PB).most_common(1) -# likely_pb = [v[0] for v in most_common_pb] -# frequency_pb = [v[-1] for v in most_common_pb] sorted_nums = sorted(likely_nums) total_freq = sum(frequency) -Chance = frac(total_freq, 10000) # Chance = number call freq / all possible numbers i.e. 11238513 +Chance = frac(total_freq, 1000) # Chance = number call freq / all possible numbers i.e. 1000 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers} \n" +#f"With percent chance of winning being {Chance}") d = dict(((k, eval (k)) for k in ('Winning_Numbers','Chance'))) h = 'Winning_Numbers', 'Chance' diff --git a/daily4.py b/daily4.py index 19a6907..8e1c477 100755 --- a/daily4.py +++ b/daily4.py @@ -1,55 +1,28 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -url = 'https://wvlottery.com/draw-games/daily-4/?game-analyze=daily-4&what-to-search=historysearch&date-range=-1' -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" -} +def get_data(): + url = 'https://wvlottery.com/draw-games/daily-4/?game-analyze=daily-4&what-to-search=historysearch&date-range=-1' + 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" + } + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + return date, nums -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers']] -# Print Table -#print(df2) - -# To excel file -df2.to_excel('./daily4.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("daily4.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -#PB = list(df['PB'].astype('int')) -#appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -#index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='daily4.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='daily4.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums = get_data() # Formatting hyphenfree = [] @@ -62,18 +35,15 @@ for n in range(0, 9): most_common= Counter(sep).most_common(4) likely_nums = [v[0] for v in most_common] frequency = [v[-1] for v in most_common] - -#for n in range(0, 26): -# most_common_pb = Counter(PB).most_common(1) -# likely_pb = [v[0] for v in most_common_pb] -# frequency_pb = [v[-1] for v in most_common_pb] sorted_nums = sorted(likely_nums) total_freq = sum(frequency) -Chance = frac(total_freq, 10000) # Chance = number call freq / all possible numbers i.e. 11238513 +Chance = frac(total_freq, 10000) # Chance = number call freq / all possible numbers i.e. 10000 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers}, \n" +#f"With percent chance of winning being {Chance}") + d = dict(((k, eval (k)) for k in ('Winning_Numbers','Chance'))) h = 'Winning_Numbers', 'Chance' f = open('d4_ans.csv', 'w', encoding='utf_8') diff --git a/la_ans.csv b/la_ans.csv index fc335e1..79e7cba 100644 --- a/la_ans.csv +++ b/la_ans.csv @@ -1,2 +1,2 @@ Winning_Numbers,SB,Chance -1-10-32-49-8,[9],1/265200 +1-10-27-32-8,[9],1/270725 diff --git a/lotto_america.py b/lotto_america.py index 32a8392..58d509a 100755 --- a/lotto_america.py +++ b/lotto_america.py @@ -1,56 +1,31 @@ # WVLottopy: Matteo DiBiagio #from django_lottopy.lottopy_site.lottopy.lottopy_web_edition.megamil import Winning_Numbers from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -url = 'https://wvlottery.com/draw-games/lotto-america/?game-analyze=lotto-america&what-to-search=historysearch&date-range=-1' -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" -} +def get_data(): + url = 'https://wvlottery.com/draw-games/lotto-america/?game-analyze=lotto-america&what-to-search=historysearch&date-range=-1' + 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" + } -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers', 'SB', 'All Star']] -# Print Table -#print(df2) + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers', 'SB', 'All Star']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + SBs = list(df2['SB'].astype('int')) + return date, nums, SBs -# To excel file -df2.to_excel('./lotto_america.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("lotto_america.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -PBs = list(df['SB'].astype('int')) -#appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='lotto_america.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='lotto_america.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums, SBs = get_data() # Formatting hyphenfree = [] @@ -65,16 +40,18 @@ for n in range(0, 52): frequency = [v[-1] for v in most_common] for n in range(0, 10): - most_common_pb = Counter(PBs).most_common(1) - SB = [v[0] for v in most_common_pb] - frequency_pb = [v[-1] for v in most_common_pb] + most_common_sb = Counter(SBs).most_common(1) + SB = [v[0] for v in most_common_sb] + frequency_sb = [v[-1] for v in most_common_sb] sorted_nums = sorted(likely_nums) -total_freq = sum(frequency + frequency_pb) -Chance = frac(total_freq, 25989600) # Chance = number call freq / all possible numbers i.e. 11238513 +total_freq = sum(frequency + frequency_sb) +Chance = frac(total_freq, 25989600) # Chance = number call freq / all possible numbers i.e. 25,989,600 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "SB:", likely_pb, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers} SB: {SB}\n" +#f"With percent chance of winning being {Chance}") + d = dict(((k, eval (k)) for k in ('Winning_Numbers', 'SB', 'Chance'))) h = 'Winning_Numbers', 'SB', 'Chance' f = open('la_ans.csv', 'w', encoding='utf_8') diff --git a/lottopy_pb.py b/lottopy_pb.py index 3caa9a5..bc41372 100755 --- a/lottopy_pb.py +++ b/lottopy_pb.py @@ -1,58 +1,29 @@ # WVLottopy: Matteo DiBiagio from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -def fraction_ratio(i): - return i/sum(i) +def get_data(): + url = 'https://wvlottery.com/draw-games/powerball/?game-analyze=powerball&what-to-search=historysearch&date-range=-1' + 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" + } + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers', 'PB', 'PPX', 'Winners WV Only', 'Payout WV Only']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + PBs = list(df2['PB'].astype('int')) + return date, nums, PBs -url = 'https://wvlottery.com/draw-games/powerball/?game-analyze=powerball&what-to-search=historysearch&date-range=-1' -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" -} - -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers', 'PB', 'PPX', 'Winners WV Only', 'Payout WV Only']] -# Print Table -#print(df2) - -# To excel file -df2.to_excel('./lotto.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("lotto.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -PBs = list(df['PB'].astype('int')) -appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='lotto.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='lotto.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums, PBs = get_data() # Formatting hyphenfree = [] @@ -62,7 +33,7 @@ splitlist = ", ".join(hyphenfree) sep = splitlist.split(", ") 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] frequency = [v[-1] for v in most_common] @@ -73,10 +44,11 @@ for n in range(0, 26): sorted_nums = sorted(likely_nums) total_freq = sum(frequency + frequency_pb) -Chance = frac(total_freq, 292201338) # Chance = number call freq / all possible numbers i.e. 11238513 +Chance = frac(total_freq, 292201338) # Chance = number call freq / all possible numbers i.e. 292201338 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "PB:", likely_pb, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers} PB: {PB}\n" +#f"With percent chance of winning being {Chance}") d = dict(((k, eval (k)) for k in ('Winning_Numbers', 'PB', 'Chance'))) h = 'Winning_Numbers', 'PB', 'Chance' diff --git a/megamil.py b/megamil.py index f81c63f..6788a5c 100755 --- a/megamil.py +++ b/megamil.py @@ -1,55 +1,31 @@ # WVLottopy megamil: Matteo DiBiagio from fractions import Fraction as frac -from sheet2dict import Worksheet import pandas as pd import requests from collections import Counter import csv -url = 'https://wvlottery.com/draw-games/mega-millions/?game-analyze=mega-millions&what-to-search=historysearch&date-range=-1' -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" -} -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers', 'MB', 'MP']] -# Print Table -#print(df2) +def get_data(): + url = 'https://wvlottery.com/draw-games/mega-millions/?game-analyze=mega-millions&what-to-search=historysearch&date-range=-1' + 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" + } -# To excel file -df2.to_excel('./lotto_megamil.xlsx') + # Get web data + r = requests.get(url, headers=header) + dfs = pd.read_html(r.text) + pd.set_option('display.max_rows', None) + # Specifies no max rows, otherwise only shows 10 records + df = dfs[0] + df2 = df[['Date', 'Numbers', 'MB', 'MP']] + date = list(df2['Date']) + nums = list(df2['Numbers'].astype('str')) + MBs = list(df2['MB'].astype('int')) + return date, nums, MBs -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("lotto_megamil.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -PBs = list(df['MB'].astype('int')) -#appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='lotto_megamil.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='lotto_megamil.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) +date, nums, MBs = get_data() # Formatting hyphenfree = [] @@ -64,16 +40,18 @@ for n in range(0, 70): frequency = [v[-1] for v in most_common] for n in range(0, 25): - most_common_pb = Counter(PBs).most_common(1) - MB = [v[0] for v in most_common_pb] - frequency_pb = [v[-1] for v in most_common_pb] + most_common_mb = Counter(MBs).most_common(1) + MB = [v[0] for v in most_common_mb] + frequency_mb = [v[-1] for v in most_common_mb] sorted_nums = sorted(likely_nums) -total_freq = sum(frequency + frequency_pb) +total_freq = sum(frequency + frequency_mb) Chance = frac(total_freq, 302575350) # Chance = number call freq / all possible numbers i.e. 11238513 Winning_Numbers = str("-".join(sorted_nums)) -#print("Likely numbers are . . . ", sorted_nums, "MB:", likely_pb, "\n", "With percent chance of winning being", chance[0]*100, "%") +#print(f"Likely numbers are . . . {Winning_Numbers} MB: {MB}\n" +#f"With percent chance of winning being {Chance}") + d = dict(((k, eval (k)) for k in ('Winning_Numbers', 'MB', 'Chance'))) h = 'Winning_Numbers', 'MB', 'Chance' f = open('mm_ans.csv', 'w', encoding='utf_8') diff --git a/requirements.txt b/requirements.txt index ced451f..d37d055 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ pandas==1.3.5 -requests==2.26.0 -sheet2dict==0.1.1 +requests==2.26.0 \ No newline at end of file diff --git a/smartscraper.py b/smartscraper.py deleted file mode 100755 index daad455..0000000 --- a/smartscraper.py +++ /dev/null @@ -1,73 +0,0 @@ -# WVLottopy: Matteo DiBiagio -from sheet2dict import Worksheet -import pandas as pd -import requests -from collections import Counter - -url = 'https://wvlottery.com/draw-games/powerball/?game-analyze=powerball&what-to-search=historysearch&date-range=-1' -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" -} - -# Get web data -r = requests.get(url, headers=header) -dfs = pd.read_html(r.text) -pd.set_option('display.max_rows', None) -# Specifies no max rows, otherwise only shows 10 records -#print(len(dfs)) -df = dfs[0] -df2 = df[['Date', 'Numbers', 'PB', 'PPX', 'Winners WV Only', 'Payout WV Only']] -# Print Table -#print(df2) - -# To excel file -df2.to_excel('../lottopy/lotto.xlsx') - -#Insert complete path to the excel file and index of the worksheet -df = pd.read_excel("lotto.xlsx", sheet_name=0) - -# insert the name of the column as a string in brackets -date = list(df['Date']) -nums = list(df['Numbers'].astype('str')) -PB = list(df['PB'].astype('int')) -appearances = list(df2['Winners WV Only'].astype('int')) - -# Index for each row -index = [i for i in range(0,len(nums)*6)] - -# Create an object -ws = Worksheet() - -# Convert active sheet (without specifying sheet name) -ws.xlsx_to_dict(path='lotto.xlsx') - -# Convert sheet of the 'lotto.xslx' spreadsheet file. -ws.xlsx_to_dict(path='lotto.xlsx', select_sheet='Sheet1') - -# object.header returns first row with the data in a spreadsheet, object.sheet_items returns converted rows as dictionaries in the array -#print(ws.header) -#print(ws.sheet_items) - -# Formatting -hyphenfree = [] -for x in nums: - hyphenfree.append(x.replace('-',', ')) -splitlist = ", ".join(hyphenfree) -sep = splitlist.split(", ") - -for n in range(0, 69): - most_common= Counter(sep).most_common(5) - likely_nums = [v[0] for v in most_common] - frequency = [v[-1] for v in most_common] - -for n in range(0, 26): - most_common_pb = Counter(PB).most_common(1) - likely_pb = [v[0] for v in most_common_pb] - frequency_pb = [v[-1] for v in most_common_pb] - -sorted_nums = sorted(likely_nums) -total_freq = sum(frequency + frequency_pb) -chance = [(total_freq / 292201338) * 100] # Chance = number call freq / all possible numbers i.e. 11238513 - -print("Likely numbers are . . . ", sorted_nums, "PB:", likely_pb, "\n", "With percent chance of winning being", chance[0]*100, "%")