forked from Cophy08/scrape_nba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_sportvu.py
74 lines (55 loc) · 5.33 KB
/
get_sportvu.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
import json
import logging
import sys
import re
from scrape import sportvu_stats
import storage.db
def main():
logging.basicConfig(filename='sportvu.log',level=logging.DEBUG, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
config=json.loads(open('config.json').read())
season = config["season"]
is_regular_season = config["is_regular_season"]
# make sure season is valid format
season_pattern = re.compile('\d{4}[-]\d{2}$')
if season_pattern.match(season) == None:
print "Invalid Season format. Example format: 2014-15"
sys.exit(0)
year = season.split("-")[0]
if is_regular_season == 0:
season_type = "Playoffs"
elif is_regular_season == 1:
season_type = "Regular+Season"
else:
print "Invalid is_regular_season value. Use 0 for regular season, 1 for playoffs"
db_storage = storage.db.Storage(config['host'], config['username'], config['password'], config['database'])
try:
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "CatchShoot"), "sportvu_catch_shoot", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "CatchShoot"), "sportvu_catch_shoot_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Defense"), "sportvu_defense", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Defense"), "sportvu_defense_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Drives"), "sportvu_drives", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Drives"), "sportvu_drives_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Passing"), "sportvu_passing", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Passing"), "sportvu_passing_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "PullUpShot"), "sportvu_pull_up_shoot", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "PullUpShot"), "sportvu_pull_up_shoot_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Rebounding"), "sportvu_rebounding", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Rebounding"), "sportvu_rebounding_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Efficiency"), "sportvu_shooting", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Efficiency"), "sportvu_shooting_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "SpeedDistance"), "sportvu_speed", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "SpeedDistance"), "sportvu_speed_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "ElbowTouch"), "sportvu_elbow_touches", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "ElbowTouch"), "sportvu_elbow_touches_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "PostTouch"), "sportvu_post_touches", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "PostTouch"), "sportvu_post_touches_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "PaintTouch"), "sportvu_paint_touches", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "PaintTouch"), "sportvu_paint_touches_team", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Player", "Possessions"), "sportvu_possessions", is_regular_season)
db_storage.insert_with_date_and_season_type(sportvu_stats.get_sportvu_data_for_stat(season, season_type, "Team", "Possessions"), "sportvu_possessions_team", is_regular_season)
db_storage.commit()
except:
logging.error('sportvu not stored')
db_storage.close()
if __name__ == '__main__':
main()