Skip to content

Commit

Permalink
Options: Add a Thanks button
Browse files Browse the repository at this point in the history
Which includes a curated list of thanks + an automatically updated
patreon list.
  • Loading branch information
InfusOnWoW committed Jun 2, 2024
1 parent 23c60ca commit 7f1c7d9
Show file tree
Hide file tree
Showing 8 changed files with 513 additions and 9 deletions.
80 changes: 80 additions & 0 deletions .github/scripts/patreonupate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python3

import patreon
from patreon.schemas import pledge
import unicodedata
import os

def has_cj(text):
for char in text:
for name in ('CJK','CHINESE','KATAKANA',):
if name in unicodedata.name(char):
return True
return False

def has_k(text):
for char in text:
if "HANGUL" in unicodedata.name(char):
return True
return False

def get_names(pledges_response, all_pledges, names):
"""Function to add names from all_pledges to names list"""
for pledge in all_pledges:
if pledge.attributes()["declined_since"] == None:
patron_id = pledge.relationship('patron').id()
patron = pledges_response.find_resource_by_type_and_id('user', patron_id)
names.append(patron.attribute('full_name'))


api_client = patreon.API(os.environ['PATREON_CREATOR_ACCESS_TOKEN'])

campaign_id = api_client.fetch_campaign().data()[0].id()
pledges_response = api_client.fetch_page_of_pledges(
campaign_id,
25)

cursor = None
names = []
while True:
pledges_response = api_client.fetch_page_of_pledges(
campaign_id,
25,
cursor=cursor,
)
get_names(pledges_response, pledges_response.data(), names)
cursor = api_client.extract_cursor(pledges_response)
if not cursor:
break


names.sort(key=lambda y: y.lower())


cjnames = filter(has_cj, names)
knames = filter(lambda n: not has_cj(n) and has_k(n), names)
latinnames = filter(lambda n: not has_cj(n) and not has_k(n), names)

file = open("WeakAuras/PatreonList.lua", "w")
file.write("if not WeakAuras.IsLibsOK() then return end\n")
file.write("---@type string\n")
file.write("local AddonName = ...\n")
file.write("---@class Private\n")
file.write("local Private = select(2, ...)\n")

file.write("Private.PatreonsList = {\n")
for name in latinnames:
file.write(" [=[" + name.strip() + "]=],\n")
file.write("}\n")

file.write("Private.PatreonsListCJ = {\n")
for name in cjnames:
file.write(" [=[" + name.strip() + "]=],\n")
file.write("}\n")

file.write("Private.PatreonsListK = {\n")
for name in knames:
file.write(" [=[" + name.strip() + "]=],\n")
file.write("}\n")

file.close()
35 changes: 35 additions & 0 deletions .github/workflows/patreon-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Create Patreon Update Pull Request

on:
schedule:
- cron: "0 10 * * 1"
workflow_dispatch:

jobs:
patreonUpdate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install patreon pip
run: |
pip install patreon
shell: bash
- name: Update Patreon list
run: |
/usr/bin/env python3 .github/scripts/patreonupate.py
shell: bash
env:
PATREON_CREATOR_ACCESS_TOKEN: ${{ secrets.PATREON_CREATOR_ACCESS_TOKEN}}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
branch: update-patreonlist
commit-message: Update Patreons List
title: Update Patreon List
body: Update Patreon List
delete-branch: true

Binary file added WeakAuras/Media/Textures/waheart.tga
Binary file not shown.
Loading

0 comments on commit 7f1c7d9

Please sign in to comment.