-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathautomation.py
87 lines (66 loc) · 3.1 KB
/
automation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python2
''' Automate of running WSA Engine '''
import mysql.connector
import datetime
from Scrapers import teamPerformance
from Scrapers import performance
from Scrapers import generateBoxScoreUrls
from Scrapers import playerReference
from Scrapers import fanduel_scraper
from Scrapers import moneyLine
from Extrapilators import dailyPerformanceExtrapolation, teamPerformanceExtrapolation, teamVsDefenseExtrapolation
from Extrapilators import sumPoints, fill_features
from MachineLearning import predict
def main():
''' Script to automate running of all basketball engine daily '''
run_scrapers()
def run_scrapers():
''' Run the scrapers '''
cnx = mysql.connector.connect(user="wsa",
host='34.68.250.121',
database="basketball",
password="")
cursor = cnx.cursor(buffered=True)
cursor = cnx.cursor()
now = datetime.datetime.now()
# now = now - datetime.timedelta(days=1)
yesterday = now - datetime.timedelta(days=1)
print str(now.year)+ "-" + str(now.month) + "-" + str(now.day)
print str(yesterday.year)+ "-" + str(yesterday.month) + "-" + str(yesterday.day)
date = str(now.year)+ "-" + str(now.month) + "-" + str(now.day)
# first figure out what day it is through some way
# get current date
findGame = "SELECT iddates FROM new_dates WHERE date = %s"
findGameData = (date,)
# then query database to get that dateI
cursor.execute(findGame, findGameData)
dateID = cursor.fetchall()[0][0]
# run player reference scaper
playerReference.scrapeHtml(cursor, cnx)
# run generate box score urls
generateBoxScoreUrls.generateBasketballReferenceURLs(cursor, cnx, yesterday.year, yesterday.month, yesterday.day)
# run performance
print "Running Perforamnce DateID:", dateID-1
performance.updateAndInsertPlayerRef(yesterday.day, yesterday.month, yesterday.year, yesterday.day, yesterday.month, yesterday.year, cursor, cnx)
# run team performance
print "Running Team Performance DateID:", dateID-1
teamPerformance.statsFiller(yesterday.day, yesterday.month, yesterday.year, yesterday.day, yesterday.month, yesterday.year, cnx, cursor)
print "Extrapolating:", dateID
dailyPerformanceExtrapolation.auto(dateID,cnx, cursor)
teamPerformanceExtrapolation.auto(dateID, cnx, cursor)
teamVsDefenseExtrapolation.auto(dateID, cnx, cursor)
# sum fanduel and draftkings points
sumPoints.sum_points(dateID, cursor, cnx)
# starts the prediction section
# fandual scraper
fanduel_scraper.insert_into_performance(cursor, cnx, dateID)
# money scraper
# moneyLine.clear_table(cursor, cnx)
# moneyLine.InsertGameOdds(cursor, cnx, 16, 10, 2018, yesterday.day, yesterday.month, yesterday.year)
# moneyLine.InsertGameSpread(cursor, cnx, 16, 10, 2018, yesterday.day, yesterday.month, yesterday.year)
# fill fetaures
fill_features.fill_futures(dateID, cnx, cursor)
# machine learning stuff
predict.makeProjections(["mlp", "ridge"],dateID, cursor, cnx)
if __name__=="__main__":
main()