Second commit

This commit is contained in:
Elia el Lazkani 2021-03-09 00:40:43 +01:00
commit 7dfbcf1b29
3 changed files with 102 additions and 0 deletions

12
.gitignore vendored Normal file
View file

@ -0,0 +1,12 @@
.DS_Store
.idea
*.log
tmp/
*.py[cod]
*.egg
build
htmlcov
score.csv
.python-version

22
README.md Normal file
View file

@ -0,0 +1,22 @@
ncaabython
==========
Quick and dirty `NCAAB` score exporter.
Usage
-----
``` text
usage: ncaabython.py [-h] [-s START_DATE] [-e END_DATE]
Get NCAAB Boxscores
optional arguments:
-h, --help show this help message and exit
-s START_DATE, --start-date START_DATE
Date to start the search from (format: 2018-12-30)
-e END_DATE, --end-date END_DATE
Date to end the search at (format: 2018-12-30)
Get NCAAB Boxscores
```

68
ncaabython.py Normal file
View file

@ -0,0 +1,68 @@
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()