-
Notifications
You must be signed in to change notification settings - Fork 15
/
json_writer.py
78 lines (71 loc) · 2.8 KB
/
json_writer.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
75
76
77
78
""" This module contains a function that writes data to a JSON file. """
import json
def write_to_json(
contributors,
filename,
start_date,
end_date,
organization,
repository_list,
sponsor_info,
link_to_profile,
):
"""Write data to a JSON file.
Args:
contributors (list): A list of Contributor objects.
filename (str): The name of the JSON file.
start_date (str): The start date of the date range for the contributor list.
end_date (str): The end date of the date range for the contributor list.
organization (str): The organization for which the contributors are being listed.
repository_list (list): A list of repositories for which the contributors are being listed.
sponsor_info (str): A string indicating whether sponsor information should be included.
link_to_profile (str): A string indicating whether a link to the contributor's profile should be included.
Returns:
None
"""
# Prepare data for JSON such that it looks like the markdown data. ie.
# {
# "start_date": "2024-03-08",
# "end_date": "2024-03-15",
# "organization": null,
# "repository_list": [
# "github/stale-repos",
# "github/issue-metrics",
# "github/contributors",
# "github/automatic-contrib-prs",
# "github/evergreen",
# "github/cleanowners"
# ],
# "sponsor_info": false,
# "link_to_profile": false,
# "contributors": [
# {
# "username": "zkoppert",
# "new_contributor": false,
# "avatar_url": "https://avatars.githubusercontent.com/u/6935431?v=4",
# "contribution_count": 785,
# "commit_url": "https://github.com/github/stale-repos/commits?author=zkoppert&since=2024-03-08&until=2024-03-15,
# "sponsor_info": ""
# },
# {
# "username": "jmeridth",
# "new_contributor": false,
# "avatar_url": "https://avatars.githubusercontent.com/u/35014?v=4",
# "contribution_count": 94,
# "commit_url": "https://github.com/github/stale-repos/commits?author=jmeridth&since=2024-03-08&until=2024-03-15,
# "sponsor_info": ""
# }
# ]
# }
data = {
"start_date": start_date,
"end_date": end_date,
"organization": organization,
"repository_list": repository_list,
"sponsor_info": sponsor_info,
"link_to_profile": link_to_profile,
"contributors": [contributor.__dict__ for contributor in contributors],
}
# Write data to a JSON file
with open(filename, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)