Skip to content

Commit 3b5865f

Browse files
committed
feat: Generate member list from new sources
1 parent 14aac5d commit 3b5865f

File tree

1 file changed

+7
-89
lines changed

1 file changed

+7
-89
lines changed

tools/generate-members.py

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,20 @@
11
import requests
22
import os
33

4-
GITHUB_API_URL = "https://api.github.com/graphql"
5-
GITHUB_TOKEN = os.getenv("GH_TOKEN")
6-
ORG_NAME = "privacyguides"
7-
84
# Fetch members from the API
9-
members_api_url = "https://discuss.privacyguides.net/g/members/members.json?offset=0&order=added_at&asc=true"
10-
headers = {
11-
"Api-Key": os.getenv("DISCOURSE_API_KEY"),
12-
"Api-Username": "system"
13-
}
14-
members_response = requests.get(members_api_url, headers=headers)
15-
members_data = members_response.json()
16-
17-
if 'members' not in members_data:
18-
raise KeyError("Response JSON does not contain 'members' key")
5+
members_api_url = os.getenv('MEMBERS_API_URL', 'https://ghost.privacyguides.org/cache/members.json')
6+
members_response = requests.get(members_api_url)
7+
members_data = members_response.json()[0]
198

209
members = members_data['members']
21-
public_members_count = 0
22-
private_members_count = 0
2310

2411
html_output = ""
2512
for member in members:
26-
flair_name = member.get('flair_name')
27-
title = member.get('title')
28-
if flair_name == "members" or title == "Member":
29-
username = member['username']
30-
avatar_template = member['avatar_template']
31-
avatar_url = f"https://discuss.privacyguides.net{avatar_template.replace('{size}', '128')}"
32-
profile_url = f"https://discuss.privacyguides.net/u/{username}"
33-
html_output += f'<a href="{profile_url}" target="_blank" title="@{username}" class="mdx-donors__item"><img loading="lazy" src="{avatar_url}"></a>'
34-
public_members_count += 1
35-
36-
# print(html_output)
37-
38-
query = """
39-
{
40-
organization(login: "%s") {
41-
sponsorshipsAsMaintainer(first: 100) {
42-
nodes {
43-
sponsorEntity {
44-
... on User {
45-
login
46-
avatarUrl
47-
url
48-
}
49-
... on Organization {
50-
login
51-
avatarUrl
52-
url
53-
}
54-
}
55-
createdAt
56-
}
57-
}
58-
}
59-
}
60-
""" % ORG_NAME
61-
62-
headers = {
63-
"Authorization": f"Bearer {GITHUB_TOKEN}",
64-
"Content-Type": "application/json"
65-
}
66-
67-
response = requests.post(GITHUB_API_URL, json={'query': query}, headers=headers)
68-
data = response.json()
69-
70-
if 'errors' in data:
71-
raise Exception(f"GraphQL query failed with errors: {data['errors']}")
72-
if 'data' not in data:
73-
raise KeyError(f"Response JSON does not contain 'data' key: {data}")
74-
75-
sponsors = data['data']['organization']['sponsorshipsAsMaintainer']['nodes']
76-
77-
# Sort sponsors by the date they began their sponsorship
78-
sponsors.sort(key=lambda x: x['createdAt'])
79-
80-
for sponsor in sponsors:
81-
sponsor_entity = sponsor['sponsorEntity']
82-
login = sponsor_entity['login']
83-
avatar_url = sponsor_entity['avatarUrl']
84-
url = sponsor_entity['url']
85-
html_output += f'<a href="{url}" title="@{login}" rel="ugc nofollow" target="_blank" class="mdx-donors__item"><img loading="lazy" src="{avatar_url}&size=120"></a>'
86-
87-
# Fetch the number of active members from the Magic Grants API
88-
magic_grants_url = "https://donate.magicgrants.org/api/active-members?fund=privacyguides"
89-
magic_grants_response = requests.get(magic_grants_url)
90-
magic_grants_data = magic_grants_response.json()
91-
92-
if 'members_count' not in magic_grants_data:
93-
raise KeyError("Response JSON does not contain 'members_count' key")
94-
95-
private_members_count += magic_grants_data['members_count']
96-
private_members_count -= public_members_count
13+
username = member['username']
14+
html_output += f'<a href="{member['url']}" target="_blank" title="@{member['username']}" class="mdx-donors__item"><img loading="lazy" src="{member['avatar']}"></a>'
9715

9816
# Append the count of private members
99-
if private_members_count > 0:
100-
html_output += f'<a href="https://donate.magicgrants.org/privacyguides" class="mdx-donors__item mdx-donors__item--private">+{private_members_count}</a>'
17+
if members_data['unaccounted'] > 0:
18+
html_output += f'<a href="https://donate.magicgrants.org/privacyguides" class="mdx-donors__item mdx-donors__item--private">+{members_data["unaccounted"]}</a>'
10119

10220
print(html_output)

0 commit comments

Comments
 (0)