Sponsorship auto-generate v0.1.5

This commit is contained in:
Jokob-sk
2024-01-30 22:45:49 +11:00
parent 8260759f12
commit d6e47541a5

View File

@@ -12,7 +12,7 @@ def fetch_sponsors():
"Accept": "application/vnd.github.v4+json", "Accept": "application/vnd.github.v4+json",
} }
# GraphQL query to fetch sponsors # GraphQL query to fetch public sponsors
graphql_query = """ graphql_query = """
{ {
user(login: "jokob-sk") { user(login: "jokob-sk") {
@@ -48,7 +48,6 @@ def fetch_sponsors():
response = requests.post(graphql_url, json={"query": graphql_query}, headers=headers) response = requests.post(graphql_url, json={"query": graphql_query}, headers=headers)
data = response.json() data = response.json()
print(f"Debug GraphQL query result: {data}") print(f"Debug GraphQL query result: {data}")
if "errors" in data: if "errors" in data:
@@ -59,10 +58,16 @@ def fetch_sponsors():
sponsors = [] sponsors = []
for sponsorship in sponsorships: for sponsorship in sponsorships:
privacy_level = sponsorship["privacyLevel"]
# Only include sponsors with privacyLevel set to "PUBLIC"
if privacy_level == "PUBLIC":
sponsor_entity = sponsorship["sponsorEntity"] sponsor_entity = sponsorship["sponsorEntity"]
created_at = datetime.strptime(sponsorship["createdAt"], "%Y-%m-%dT%H:%M:%SZ") created_at = datetime.strptime(sponsorship["createdAt"], "%Y-%m-%dT%H:%M:%SZ")
privacy_level = sponsorship["privacyLevel"]
monthly_price = sponsorship["tier"]["monthlyPriceInCents"] # Check if tier is not None before accessing its properties
tier = sponsorship.get("tier", {})
monthly_price = tier.get("monthlyPriceInCents") if tier else None
sponsor = { sponsor = {
"name": sponsor_entity.get("name"), "name": sponsor_entity.get("name"),
@@ -75,11 +80,12 @@ def fetch_sponsors():
sponsors.append(sponsor) sponsors.append(sponsor)
print("All Sponsors:") print("Public Sponsors:")
print(sponsors) print(sponsors)
return {"sponsors": sponsors} return {"sponsors": sponsors}
def generate_sponsors_table(sponsors): def generate_sponsors_table(sponsors):
sponsors_table = "| All Sponsors |\n|---|\n" sponsors_table = "| All Sponsors |\n|---|\n"
for sponsor in sponsors: for sponsor in sponsors: