Sponsorship auto-generate v0.1.50

This commit is contained in:
Jokob-sk
2024-01-28 23:32:27 +11:00
parent 8e603fd5f9
commit 1f9fc71416
4 changed files with 20 additions and 34 deletions

View File

@@ -61,7 +61,7 @@ jobs:
type=sha
- name: Log in to Github Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: jokob-sk
@@ -69,7 +69,7 @@ jobs:
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

View File

@@ -59,7 +59,7 @@ jobs:
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }}
- name: Log in to Github Container registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: jokob-sk
@@ -67,7 +67,7 @@ jobs:
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

View File

@@ -2,7 +2,7 @@ name: Update Sponsors Table
on:
schedule:
- cron: '40 11 * * *' # Set your preferred schedule (UTC)
- cron: '35 12 * * *' # Set your preferred schedule (UTC)
jobs:
update-table:

View File

@@ -1,6 +1,7 @@
import os
import requests
import base64
from datetime import datetime
def fetch_sponsors():
global headers
@@ -50,15 +51,14 @@ def fetch_sponsors():
if "errors" in data:
print(f"GraphQL query failed: {data['errors']}")
return {"current_sponsors": [], "past_sponsors": []}
return {"sponsors": []}
sponsorships = data["data"]["viewer"]["sponsorshipsAsMaintainer"]["nodes"]
current_sponsors = []
past_sponsors = []
sponsors = []
for sponsorship in sponsorships:
sponsor_entity = sponsorship["sponsorEntity"]
created_at = sponsorship["createdAt"]
created_at = datetime.strptime(sponsorship["createdAt"], "%Y-%m-%dT%H:%M:%SZ")
privacy_level = sponsorship["privacyLevel"]
monthly_price = sponsorship["tier"]["monthlyPriceInCents"]
@@ -71,31 +71,19 @@ def fetch_sponsors():
"monthly_price": monthly_price,
}
# Check if the sponsorship is current or past
if created_at == sponsorship["createdAt"]:
past_sponsors.append(sponsor)
else:
current_sponsors.append(sponsor)
sponsors.append(sponsor)
print("Current Sponsors:")
print(current_sponsors)
print("\nPast Sponsors:")
print(past_sponsors)
print("All Sponsors:")
print(sponsors)
return {"current_sponsors": current_sponsors, "past_sponsors": past_sponsors}
return {"sponsors": sponsors}
def generate_sponsors_table(sponsors):
sponsors_table = "| All Sponsors |\n|---|\n"
for sponsor in sponsors:
sponsors_table += f"| [{sponsor['name'] or sponsor['login']}]({sponsor['url']}) - ${sponsor['monthly_price'] / 100:.2f} |\n"
def generate_sponsors_table(current_sponsors, past_sponsors):
current_table = "| Current Sponsors |\n|---|\n"
for sponsor in current_sponsors:
current_table += f"| [{sponsor['name'] or sponsor['login']}]({sponsor['url']}) - ${sponsor['monthly_price'] / 100:.2f} |\n"
past_table = "| Past Sponsors |\n|---|\n"
for sponsor in past_sponsors:
past_table += f"| [{sponsor['name'] or sponsor['login']}]({sponsor['url']}) - ${sponsor['monthly_price'] / 100:.2f} |\n"
return current_table + "\n" + past_table
return sponsors_table
def update_readme(sponsors_table):
global headers
@@ -153,13 +141,11 @@ def update_readme(sponsors_table):
print("README.md updated successfully with the sponsors table.")
def main():
sponsors_data = fetch_sponsors()
current_sponsors = sponsors_data.get("current_sponsors", [])
past_sponsors = sponsors_data.get("past_sponsors", [])
sponsors = sponsors_data.get("sponsors", [])
sponsors_table = generate_sponsors_table(current_sponsors, past_sponsors)
sponsors_table = generate_sponsors_table(sponsors)
update_readme(sponsors_table)
if __name__ == "__main__":