Skip to content

Commit 17b80e1

Browse files
Create extract_contribution_details.py
1 parent 282c614 commit 17b80e1

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import csv
3+
import re
4+
from github import Github
5+
6+
# Load GitHub credentials
7+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
8+
GITHUB_REPOSITORY = os.getenv("GITHUB_REPOSITORY")
9+
10+
# Authenticate with GitHub
11+
g = Github(GITHUB_TOKEN)
12+
repo = g.get_repo(GITHUB_REPOSITORY)
13+
14+
print("🔍 Fetching open GitHub issues with 'ambassador' label...")
15+
issues = list(repo.get_issues(state="open", labels=["ambassador"]))
16+
print(f"✅ Found {len(issues)} issues")
17+
18+
# Define helper function to extract field content by label
19+
def extract(label, body):
20+
pattern = rf"{re.escape(label)}\s*\n+(.+?)(\n\S|\Z)"
21+
match = re.search(pattern, body, re.DOTALL)
22+
return match.group(1).strip() if match else ""
23+
24+
# Create output list
25+
output_rows = []
26+
27+
for issue in issues:
28+
body = issue.body or ""
29+
output_rows.append({
30+
"Submission ID": issue.number,
31+
"How Would the Nominee Contribute as an Ambassador?": extract("🏆 How Would the Nominee Contribute as an Ambassador?", body),
32+
"Any Additional Details": extract("Any additional details you'd like to share?", body)
33+
})
34+
35+
# Write to CSV
36+
os.makedirs("ambassador", exist_ok=True)
37+
with open("ambassador/contribution_details.csv", "w", newline='', encoding="utf-8") as f:
38+
writer = csv.DictWriter(f, fieldnames=output_rows[0].keys())
39+
writer.writeheader()
40+
writer.writerows(output_rows)
41+
42+
print("📄 File written to ambassador/contribution_details.csv")

0 commit comments

Comments
 (0)