69 lines
1.5 KiB
Python
69 lines
1.5 KiB
Python
|
import csv
|
||
|
import argparse
|
||
|
from datetime import datetime
|
||
|
from sportsipy.ncaab.boxscore import Boxscores
|
||
|
|
||
|
|
||
|
def save_score(boxscores):
|
||
|
score = []
|
||
|
for day, games in boxscores.games.items():
|
||
|
if games:
|
||
|
for game in games:
|
||
|
game['date'] = day
|
||
|
score.append(game)
|
||
|
header = score[0].keys()
|
||
|
|
||
|
with open('score.csv', 'w', newline='') as f:
|
||
|
dict_writer = csv.DictWriter(f, header)
|
||
|
dict_writer.writeheader()
|
||
|
dict_writer.writerows(score)
|
||
|
|
||
|
|
||
|
def print_score(boxscores):
|
||
|
print(boxscores.games)
|
||
|
|
||
|
|
||
|
def get_boxscores(start_date, end_date):
|
||
|
return Boxscores(date_parser(start_date), date_parser(end_date))
|
||
|
|
||
|
|
||
|
def date_parser(date):
|
||
|
return datetime(int(date[:4]), int(date[5:7]), int(date[8:10]))
|
||
|
|
||
|
|
||
|
def main():
|
||
|
parser = argumentparser()
|
||
|
boxscores = get_boxscores(parser.start_date, parser.end_date)
|
||
|
save_score(boxscores)
|
||
|
#print_score(boxscores)
|
||
|
|
||
|
|
||
|
def argumentparser():
|
||
|
parser = argparse.ArgumentParser(
|
||
|
description="""Get NCAAB Boxscores""",
|
||
|
epilog="""Get NCAAB Boxscores""",
|
||
|
formatter_class=argparse.RawTextHelpFormatter,
|
||
|
)
|
||
|
|
||
|
parser.add_argument(
|
||
|
"-s",
|
||
|
"--start-date",
|
||
|
default=None,
|
||
|
type=str,
|
||
|
help="""Date to start the search from (format: 2018-12-30)""",
|
||
|
)
|
||
|
|
||
|
parser.add_argument(
|
||
|
"-e",
|
||
|
"--end-date",
|
||
|
default=None,
|
||
|
type=str,
|
||
|
help="""Date to end the search at (format: 2018-12-30)""",
|
||
|
)
|
||
|
|
||
|
return parser.parse_args()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|