From 1f9fc714161005af208a8813ebbfe43ff7c8f189 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sun, 28 Jan 2024 23:32:27 +1100 Subject: [PATCH] Sponsorship auto-generate v0.1.50 --- .github/workflows/docker_dev.yml | 4 +- .github/workflows/docker_prod.yml | 4 +- .github/workflows/update_sponsors_table.yml | 2 +- update_sponsors.py | 44 +++++++-------------- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/.github/workflows/docker_dev.yml b/.github/workflows/docker_dev.yml index 22a6f6df..ca163737 100755 --- a/.github/workflows/docker_dev.yml +++ b/.github/workflows/docker_dev.yml @@ -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 }} diff --git a/.github/workflows/docker_prod.yml b/.github/workflows/docker_prod.yml index a4bb5817..6b5e7709 100755 --- a/.github/workflows/docker_prod.yml +++ b/.github/workflows/docker_prod.yml @@ -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 }} diff --git a/.github/workflows/update_sponsors_table.yml b/.github/workflows/update_sponsors_table.yml index d5516d24..1b87a1d5 100755 --- a/.github/workflows/update_sponsors_table.yml +++ b/.github/workflows/update_sponsors_table.yml @@ -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: diff --git a/update_sponsors.py b/update_sponsors.py index c332b35b..40f7c796 100755 --- a/update_sponsors.py +++ b/update_sponsors.py @@ -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__":