Skip to content

Commit

Permalink
Sponsorship auto-generate v0.1.50
Browse files Browse the repository at this point in the history
  • Loading branch information
jokob-sk committed Jan 28, 2024
1 parent 8e603fd commit 1f9fc71
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ 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
password: ${{ secrets.GITHUB_TOKEN }}

- 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 }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ 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
password: ${{ secrets.GITHUB_TOKEN }}

- 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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_sponsors_table.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
44 changes: 15 additions & 29 deletions update_sponsors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import requests
import base64
from datetime import datetime

def fetch_sponsors():
global headers
Expand Down Expand Up @@ -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"]

Expand All @@ -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
Expand Down Expand Up @@ -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__":
Expand Down

0 comments on commit 1f9fc71

Please sign in to comment.