BraydenMoore commited on
Commit
74571f6
1 Parent(s): 576dcf1

update update.py

Browse files
Files changed (1) hide show
  1. Source/Build/update.py +65 -1
Source/Build/update.py CHANGED
@@ -1,11 +1,15 @@
 
1
  import build
2
  import datetime as dt
3
  import numpy as np
 
4
  import pandas as pd
5
  pd.set_option('chained_assignment',None)
6
  pd.set_option('display.max_columns',None)
7
  import os
8
  import pickle as pkl
 
 
9
 
10
  current_directory = os.path.dirname(os.path.abspath(__file__))
11
  parent_directory = os.path.dirname(current_directory)
@@ -33,9 +37,69 @@ file_path = os.path.join(pickle_directory, 'schedule.pkl')
33
  with open(file_path, 'wb') as f:
34
  pkl.dump(df, f)
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  # update current season
37
  build.build_gbg_data(get_seasons=[current_season])
38
- #build.build_gbg_data(get_seasons=range(2014,2024))
39
  build.add_odds_data()
40
 
41
  # get winners
 
1
+ import nfl_data_py.nfl_data_py as nfl
2
  import build
3
  import datetime as dt
4
  import numpy as np
5
+ import io
6
  import pandas as pd
7
  pd.set_option('chained_assignment',None)
8
  pd.set_option('display.max_columns',None)
9
  import os
10
  import pickle as pkl
11
+ import requests
12
+ from bs4 import BeautifulSoup
13
 
14
  current_directory = os.path.dirname(os.path.abspath(__file__))
15
  parent_directory = os.path.dirname(current_directory)
 
37
  with open(file_path, 'wb') as f:
38
  pkl.dump(df, f)
39
 
40
+ def get_week():
41
+ headers = {
42
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
43
+ 'Accept-Encoding': 'gzip, deflate',
44
+ 'Accept-Language': 'en-US,en;q=0.9',
45
+ 'Cache-Control': 'max-age=0',
46
+ 'Connection': 'keep-alive',
47
+ 'Dnt': '1',
48
+ 'Upgrade-Insecure-Requests': '1',
49
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
50
+ }
51
+ url = 'https://www.nfl.com/schedules/'
52
+ resp = requests.get(url,headers=headers)
53
+ soup = BeautifulSoup(resp.text, 'html.parser')
54
+ h2_tags = soup.find_all('h2')
55
+ year = h2_tags[0].getText().split(' ')[0]
56
+ week = h2_tags[0].getText().split(' ')[-1]
57
+ return int(week), int(year)
58
+
59
+ def get_lines(season):
60
+ url = 'https://www.sportsbettingdime.com/nfl/public-betting-trends/'
61
+ response = requests.get(url)
62
+ html = BeautifulSoup(response.text)
63
+ week = html.find_all('h2')[0].get_text().split(' ')[-1]
64
+ df = pd.read_html(io.StringIO(response.text))
65
+
66
+ columns = list(df[0].loc[0,:].values)
67
+ columns = columns[:2] + columns[3:]
68
+
69
+ data_list = []
70
+ for data in df[1:-1]:
71
+ data.columns = columns
72
+ data['Matchup'] = data['Matchup'].str.extract('([A-Z]+)[^A-Za-z]*$')
73
+ data_dict = {
74
+ 'season' : season,
75
+ 'week' : week,
76
+ 'home_team' : data['Matchup'][1],
77
+ 'away_team' : data['Matchup'][0],
78
+ 'away_spread' : float(data.iloc[0,4].replace('+','')),
79
+ 'money_on_away_ats' : int(data.iloc[0,5].replace('%',''))/100,
80
+ 'bets_on_away_ats' : int(data.iloc[0,6].replace('%',''))/100,
81
+ 'away_moneyline' : int(data['moneyline'][0].replace('+','')),
82
+ 'money_on_away_ml' : int(data.iloc[0,8].replace('%',''))/100,
83
+ 'bets_on_away_ml' : int(data.iloc[0,9].replace('%',''))/100,
84
+ 'over_under' : data['total'].str.replace('o','').str.replace('u','').astype(float).mean(),
85
+ 'money_on_over' : int(data.iloc[0,11].replace('%',''))/100,
86
+ 'bets_on_over' : int(data.iloc[0,12].replace('%',''))/100
87
+ }
88
+ data_list.append(data_dict)
89
+
90
+ betting_data = pd.DataFrame(data_list)
91
+ betting_data['key'] = [f'{season}_{week}_{away}_{home}' for season, week, away, home in betting_data[['season','week','away_team','home_team']].values]
92
+ return betting_data
93
+
94
+ current_week = get_week()[0]
95
+ the_week = {'week':current_week,
96
+ 'year':current_season}
97
+ file_path = os.path.join(pickle_directory, 'the_week.pkl')
98
+ with open(file_path, 'wb') as f:
99
+ pkl.dump(the_week, f)
100
+
101
  # update current season
102
  build.build_gbg_data(get_seasons=[current_season])
 
103
  build.add_odds_data()
104
 
105
  # get winners