-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathfetch-newspack-repos.py
58 lines (45 loc) · 1.53 KB
/
fetch-newspack-repos.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
import requests
import csv
# Constants
github_account = "Automattic"
repo_prefix = "newspack-"
output_file = "newspack_repos.csv"
def fetch_repos(account):
url = f"https://api.github.com/users/{account}/repos"
repos = []
page = 1
while True:
response = requests.get(url, params={"per_page": 100, "page": page})
if response.status_code != 200:
print(f"Error: Unable to fetch repositories (status code {response.status_code})")
break
data = response.json()
if not data:
break
repos.extend(data)
page += 1
return repos
def filter_repos(repos, prefix):
return [
{
"name": repo["name"],
"created_at": repo["created_at"]
}
for repo in repos if repo["name"].startswith(prefix)
]
def write_to_csv(repos, filename):
with open(filename, mode="w", newline="", encoding="utf-8") as file:
writer = csv.writer(file)
writer.writerow(["Repository Name", "Creation Date"])
for repo in repos:
writer.writerow([repo["name"], repo["created_at"]])
def main():
print(f"Fetching repositories for account: {github_account}...")
repos = fetch_repos(github_account)
print(f"Filtering repositories with prefix: {repo_prefix}...")
filtered_repos = filter_repos(repos, repo_prefix)
print(f"Writing results to {output_file}...")
write_to_csv(filtered_repos, output_file)
print(f"Done! Results saved to {output_file}")
if __name__ == "__main__":
main()