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

View File

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

View File

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