From ecdc7e4f220599198aea50cae294b634d416afea Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 6 Jan 2018 17:22:41 -0500 Subject: [PATCH] Add liberapay integration --- fosspay/blueprints/html.py | 18 +++++++++++++++++- templates/goal.html | 27 ++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/fosspay/blueprints/html.py b/fosspay/blueprints/html.py index 2973f73..e8c0c11 100644 --- a/fosspay/blueprints/html.py +++ b/fosspay/blueprints/html.py @@ -13,6 +13,7 @@ import bcrypt import hashlib import stripe import binascii +import requests encoding = locale.getdefaultlocale()[1] html = Blueprint('html', __name__, template_folder='../../templates') @@ -49,12 +50,27 @@ def index(): patreon_count = 0 patreon_sum = 0 + liberapay = _cfg("liberapay-campaign") + if liberapay: + lp = (requests + .get("https://liberapay.com/{}/public.json".format(liberapay)) + ).json() + lp_count = lp['npatrons'] + lp_sum = int(float(lp['receiving']['amount']) * 100) + # Convert from weekly to monthly + lp_sum = lp_sum * 52 // 12 + else: + lp_count = 0 + lp_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) + patreon_sum=patreon_sum, + lp_count=lp_count, + lp_sum=lp_sum) @html.route("/setup", methods=["POST"]) def setup(): diff --git a/templates/goal.html b/templates/goal.html index f8a9bb2..714056a 100644 --- a/templates/goal.html +++ b/templates/goal.html @@ -2,12 +2,13 @@
- {% set total_sum = recurring_sum + patreon_sum %} - {% set total_count = recurring_count + patreon_count %} + {% set total_sum = recurring_sum + patreon_sum + lp_sum %} + {% set total_count = recurring_count + patreon_count + lp_count %} {% if _cfg("goal") %} {% set goal = int(_cfg("goal")) %} {% set recurring_progress = recurring_sum / goal %} {% set patreon_progress = patreon_sum / goal %} + {% set lp_progress = lp_sum / goal %} {% set progress = total_sum / goal %}
${{ "{:.0f}".format(patreon_sum / 100) }}
+ +
+ ${{ "{:.0f}".format(lp_sum / 100) }} +
{% endif %}
- {% if patreon_count %} + {% if patreon_count or lp_count %}

${{ "{:.2f}".format(recurring_sum / 100) }}/mo via {{ domain }} ({{ recurring_count }} supporter{{ "s" if recurring_count != 1 else "" }})

+ {% if patreon_count %}

${{ "{:.2f}".format(patreon_sum / 100) }}/mo via @@ -45,6 +54,18 @@ ({{ patreon_count }} supporter{{ "s" if patreon_count != 1 else "" }})

{% endif %} + {% if lp_count %} +

+ ${{ "{:.2f}".format(lp_sum / 100) }}/mo + via + + Liberapay + ({{ lp_count }} supporter{{ "s" if lp_count != 1 else "" }}) +

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

${{ "{:.2f}".format(total_sum / 100)}}/mo