diff --git a/config.ini.example b/config.ini.example index d1ba964..56cbc4d 100644 --- a/config.ini.example +++ b/config.ini.example @@ -66,5 +66,10 @@ patreon-campaign= # Optional LiberaPay integration, fill in your username here liberapay-campaign= +# Optional GitHub sponsors integration +# Generate personal access key at https://github.com/settings/tokens +# Must have "user" access. +github-token= + # Command to reload fosspay (send it a SIGHUP) reload-command=kill -HUP $(pgrep -xf '/usr/bin/python3.*app.py' | tail -n 1) diff --git a/cronjob.py b/cronjob.py index 11e781b..24879b0 100755 --- a/cronjob.py +++ b/cronjob.py @@ -12,7 +12,7 @@ import subprocess stripe.api_key = _cfg("stripe-secret") -print("Processing monthly donations") +print("Processing monthly donations at " + str(datetime.utcnow())) donations = Donation.query \ .filter(Donation.type == DonationType.monthly) \ diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index 9aae1ee..e6e37ca 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -70,14 +70,49 @@ def index(): lp_count = 0 lp_sum = 0 + github_token = _cfg("github-token") + if github_token: + query = """ + { + viewer { + login + sponsorsListing { + tiers(first:100) { + nodes { + monthlyPriceInCents + adminInfo { + sponsorships(includePrivate:true) { + totalCount + } + } + } + } + } + } + } + """ + r = requests.post("https://api.github.com/graphql", json={ + "query": query + }, headers={ + "Authorization": f"bearer {github_token}" + }) + result = r.json() + nodes = result["data"]["viewer"]["sponsorsListing"]["tiers"]["nodes"] + cnt = lambda n: n["adminInfo"]["sponsorships"]["totalCount"] + gh_count = sum(cnt(n) for n in nodes) + gh_sum = sum(n["monthlyPriceInCents"] * cnt(n) for n in nodes) + gh_user = result["data"]["viewer"]["login"] + else: + gh_count = 0 + gh_sum = 0 + return render_template("index.html", projects=projects, avatar=avatar, selected_project=selected_project, - recurring_count=recurring_count, - recurring_sum=recurring_sum, - patreon_count=patreon_count, - patreon_sum=patreon_sum, - lp_count=lp_count, - lp_sum=lp_sum, currency=currency) + recurring_count=recurring_count, recurring_sum=recurring_sum, + patreon_count=patreon_count, patreon_sum=patreon_sum, + lp_count=lp_count, lp_sum=lp_sum, + gh_count=gh_count, gh_sum=gh_sum, gh_user=gh_user, + currency=currency) @html.route("/setup", methods=["POST"]) def setup(): diff --git a/templates/goal.html b/templates/goal.html index e433617..2483649 100644 --- a/templates/goal.html +++ b/templates/goal.html @@ -2,8 +2,8 @@
- {% set total_sum = recurring_sum + patreon_sum + lp_sum %} - {% set total_count = recurring_count + patreon_count + lp_count %} + {% set total_sum = recurring_sum + patreon_sum + lp_sum + gh_sum %} + {% set total_count = recurring_count + patreon_count + lp_count + gh_count %} {% if _cfg("goal") %} {% set goal = int(_cfg("goal")) %} @@ -17,6 +17,7 @@ {% set recurring_progress = recurring_sum / adjusted_goal %} {% set patreon_progress = patreon_sum / adjusted_goal %} {% set lp_progress = lp_sum / adjusted_goal %} + {% set gh_progress = gh_sum / adjusted_goal %} {% set progress = total_sum / goal %}
{{ currency.amount("{:.0f}".format(lp_sum / 100)) }}
+ +
+ {{ currency.amount("{:.0f}".format(gh_sum / 100)) }} +
{% endif %}
@@ -73,6 +81,17 @@ ({{ lp_count }} supporter{{ "s" if lp_count != 1 else "" }})

{% endif %} + {% if gh_count %} +

+ {{ currency.amount("{:.2f}".format(gh_sum / 100)) }}/mo + via + + GitHub + ({{ gh_count }} supporter{{ "s" if lp_count != 1 else "" }}) +

+ {% endif %} {% endif %} {% if goal %}