-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_example.py
31 lines (24 loc) · 978 Bytes
/
csv_example.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
import csv
from pathlib import Path
from datetime import datetime
# from github_classroom import get_weeks
from github_classroom.config import assignment_from_config
from github_classroom import get_weeks
# setup some configuration
output_path = Path('weekly_commits.csv')
assignment = assignment_from_config('config.ini')
# We are fixing the range of dates in this example
start = datetime(2021, 10, 4).date()
weeks = get_weeks(start, 23)
defaults = {week : 0 for week in weeks}
with output_path.open('w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=['identifier', 'github_username', *weeks], extrasaction='ignore')
writer.writeheader()
for identifier, github_username, repo in assignment.roster():
print(identifier)
row = defaults.copy()
row['identifier'] = identifier
row['github_username'] = github_username
if repo:
row.update(dict(repo.commit_count_by_week()))
writer.writerow(row)