feat: Fetch membership count from MAGIC (#2957)

Signed-off-by: Justin Ehrenhofer <justin.ehrenhofer@gmail.com>
This commit is contained in:
Jonah Aragon 2025-03-14 14:34:21 -07:00
parent 426c5a2402
commit aaa17f0ebf
No known key found for this signature in database
2 changed files with 13 additions and 4 deletions

View File

@ -44,7 +44,7 @@ MAGIC Grants is our fiscal host, and their custom, open-source donation platform
Privacy Guides would not be possible without these individuals who generously donate on a monthly or yearly basis. (1)
{ .annotate }
1. If you [become a member](https://donate.magicgrants.org/privacyguides/membership) and [link your donation](https://discuss.privacyguides.net/t/getting-your-member-flair-on-the-forum/25453) to your forum account, you're automatically added here with a link to your profile and avatar to show your support for Privacy Guides. If you link your forum account but don't set your flair or title, you'll be a silent +1. You can change your visibility any time. This chart is updated upon each website release.
1. If you [become a member](https://donate.magicgrants.org/privacyguides/membership) and [link your donation](https://discuss.privacyguides.net/t/getting-your-member-flair-on-the-forum/25453) to your forum account, you're automatically added here with a link to your profile and avatar to show your support for Privacy Guides. If you don't make your membership public on the forum, you'll be a silent +1. You can change your visibility any time. This chart is updated upon each website release.
<div class="mdx-donors" data-mdx-component="donors">
<div class="mdx-donors__list">

View File

@ -18,6 +18,7 @@ if 'members' not in members_data:
raise KeyError("Response JSON does not contain 'members' key")
members = members_data['members']
public_members_count = 0
private_members_count = 0
html_output = ""
@ -30,8 +31,7 @@ for member in members:
avatar_url = f"https://discuss.privacyguides.net{avatar_template.replace('{size}', '128')}"
profile_url = f"https://discuss.privacyguides.net/u/{username}"
html_output += f'<a href="{profile_url}" target="_blank" title="@{username}" class="mdx-donors__item"><img loading="lazy" src="{avatar_url}"></a>'
else:
private_members_count += 1
public_members_count += 1
# print(html_output)
@ -84,7 +84,16 @@ for sponsor in sponsors:
url = sponsor_entity['url']
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>'
private_members_count += 6
# Fetch the number of active members from the Magic Grants API
magic_grants_url = "https://donate.magicgrants.org/api/active-members?fund=privacyguides"
magic_grants_response = requests.get(magic_grants_url)
magic_grants_data = magic_grants_response.json()
if 'members_count' not in magic_grants_data:
raise KeyError("Response JSON does not contain 'members_count' key")
private_members_count += magic_grants_data['members_count']
private_members_count -= public_members_count
# Append the count of private members
if private_members_count > 0: