commit 7dfbcf1b29431f641d5f858c3b622ff5f4fa5c50 Author: Elia el Lazkani Date: Tue Mar 9 00:40:43 2021 +0100 Second commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60f6ce4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +.DS_Store +.idea +*.log +tmp/ + +*.py[cod] +*.egg +build +htmlcov + +score.csv +.python-version diff --git a/README.md b/README.md new file mode 100644 index 0000000..226dc19 --- /dev/null +++ b/README.md @@ -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 +``` diff --git a/ncaabython.py b/ncaabython.py new file mode 100644 index 0000000..46c855b --- /dev/null +++ b/ncaabython.py @@ -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()